karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 24 of 143

Convert short primitive type to Short object in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 643 Views

Let us first create a short primitive type and assign a value.short val = 30;Now, create a Short object and set the above short type to it.Short myShort = new Short(val);The following is the complete example to convert short primitive type to Short object using Short constructor.Examplepublic class Demo {    public static void main(String []args) {       short val = 30;       Short myShort = new Short(val);       System.out.println(myShort);    } }Output30

Read More

Ceil and floor functions in C++

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 5K+ Views

The ceil FunctionThe ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.Here is the syntax of ceil function in C++ language,double ceil(double x); float ceil(float x);Here is an example of ceil function in C++ language,Example#include #include using namespace std; int main() {    float var = 1234.25;    float res;    res = ceil(var);    cout

Read More

Check whether a NavigableMap empty or not in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 257 Views

The isEmpty() method is used in Java to check whether a NavigableMap is empty or not.First, create a NavigableMap and add elements to it −NavigableMap n = new TreeMap(); n.put(5, "Tom"); n.put(9, "John"); n.put(14, "Jamie"); n.put(1, "Tim"); n.put(4, "Jackie"); n.put(15, "Kurt"); n.put(19, "Tiger"); n.put(24, "Jacob");Now, check whether the Map is empty or not −System.out.println("Map is empty? " + n.isEmpty());The following is an example to implement isEmpty() method and check whether the Map is empty −Exampleimport java.util.*; public class Demo {    public static void main(String[] args) {       NavigableMap n = new TreeMap();       n.put(5, "Tom"); ...

Read More

Get Day Number of Week in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 11K+ Views

To get the day of the week, use Calendar.DAY_OF_WEEK.Firstly, declare a calendar object and get the current date and time.Calendar calendar = Calendar.getInstance(); System.out.println(calendar.getTime().toString());Now, fetch the day of the week in an integer variable.int day = calendar.get(Calendar.DAY_OF_WEEK);The following is the final example.Exampleimport java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar calendar = Calendar.getInstance();       System.out.println(calendar.getTime().toString());       int day = calendar.get(Calendar.DAY_OF_WEEK);       System.out.println("Day: " + day);       int hour = calendar.get(Calendar.HOUR_OF_DAY);       System.out.println("Hour: " + hour);       int minute = calendar.get(Calendar.MINUTE); ...

Read More

Java Program to return the hexadecimal value of the supplied byte array

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 181 Views

The following is the supplied byte array −byte[] b = new byte[]{'x', 'y', 'z'};We have created a custom method “display” here and passed the byte array value. The same method converts byte array to hex string −public static String display(byte[] b1){    StringBuilder strBuilder = new StringBuilder();    for(byte val : b1){     strBuilder.append(String.format("%02x", val&0xff)); } return strBuilder.toString(); }Let us see the entire example now −Examplepublic class Demo { public static void main(String args[]) { byte[] b = new byte[]{'x', 'y', 'z'}; ...

Read More

C# Program to remove a node at the end of the Linked List

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 215 Views

The following is our LinkedList.string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"}; LinkedList list = new LinkedList(employees);Now, let’s say you need to remove the last node i.e. “Jamie”. For that, use the RemoveLast() method.list.RemoveLast();Exampleusing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"};       LinkedList list = new LinkedList(employees);       foreach (var emp in list) {          Console.WriteLine(emp);       }       // removing last node       list.RemoveLast();       Console.WriteLine("LinkedList after ...

Read More

Java Program to display Bit manipulation in Integer

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 270 Views

Let’s say we have the following decimal number, which is binary 100100110.int dec = 294;To perform bit manipulation, let us count the number of 1 bits in it. We have used bitCount() method for this purpose.Integer.bitCount(dec);The following is an example to display bit manipulation in given Integer.Examplepublic class Demo {    public static void main(String []args) {       // binary 100100110       int dec = 294;       System.out.println("Count of one bits = " + Integer.bitCount(dec));    } }OutputCount of one bits = 4

Read More

What are abstract classes in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 458 Views

Abstract classes contain abstract methods, which are implemented by the derived class. The derived classes have more specialized functionality.The following is an example showing the usage of abstract classes in C#.Exampleusing System; namespace Demo {    abstract class Shape {       public abstract int area();    }    class Rectangle: Shape {       private int length;       private int width;       public Rectangle( int a = 0, int b = 0) {          length = a;          width = b;          Console.WriteLine("Length of ...

Read More

Precision on a number format in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

You can include a precision specifier to the following format specifiers −%f %e %g %sOn floating point, the number of decimal places is known.Let’s say we declared a Formatter object −Formatter f1 = new Formatter();Now, we want 3 decimal places. For that, use 1.3f −f1.format("%1.3f", 29292929.98765432);The above will return the number with 3 decimal places −29292929.988The following is the final example −Exampleimport java.util.Formatter; public class Demo {     public static void main(String args[]) {        Formatter f1,  f2,  f3;        f1 = new Formatter();        f1.format("%1.3f",  29292929.98765432);        System.out.println(f1);        f2 = new Formatter();        f2.format("%1.7f",  29292929.98765432);        System.out.println(f2);     ...

Read More

Display Month of Year using Java Calendar

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

For using Calendar class, import the following package.import java.util.Calendar;Using the Calendar class, create an object.Calendar calendar = Calendar.getInstance();Now, create a string array of the month names.String[] month = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };Display the month name.month[calendar.get(Calendar.MONTH)]The following is an example.Exampleimport java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar calendar = Calendar.getInstance();       String[] month = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };       System.out.println("Current Month = " + month[calendar.get(Calendar.MONTH)]);   ...

Read More
Showing 231–240 of 1,421 articles
« Prev 1 22 23 24 25 26 143 Next »
Advertisements