karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 70 of 143

Format double with new DecimalFormat("0.#####E0") in Java

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

Firstly, set the double values −double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920;Now, format the double values with new DecimalFormat("0.#####E0") −System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3));The following is an example −Exampleimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920; System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3)); } }Output1.39876E0 2.39876E0 6.692E-1

Read More

Format integer values with java.text.DecimalFormat

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

Here, we are using the DecimalFormat class in Java to format integer value, which is the java.text.DecimalFormat package.Let us take the following format: DecimalFormat("0.######E0") and use the format() method for this purpose −new DecimalFormat("0.#####E0").format(5089) new DecimalFormat("0.#####E0").format(608)Since, we have used DecimalFormat class in Java, therefore importing the following package in a must −import java.text.DecimalFormat;The following is an example −Exampleimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { System.out.println(new DecimalFormat("0.#####E0").format(387979)); System.out.println(new DecimalFormat("0.#####E0").format(29797)); System.out.println(new DecimalFormat("0.#####E0").format(49788)); ...

Read More

SimpleDateFormat("hh:mm:ss a") in Java

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

The following format displays time from −hh:mm:ssThe following format displays time with AM/ PM marker −hh:mm:ss aHere, we are using the SimpleDateFormat class to display date and time. Let us set it for the format we want i.e time and AM/PM Marker −Format f = new SimpleDateFormat("hh:mm:ss a"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);The following is an example −Exampleimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ...

Read More

C++ Program to Print Number Entered by User

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

The objects “cin” and “cout” are used in C++ for input and output respectively. cin is an instance of the istream class and is attached to the standard input device such as the keyboard. cout is an instance of the ostream class and is connected to the standard output device such as the display screen.A program that prints the number entered by the user is as follows −Example#include using namespace std; int main() {    int num;    coutnum;    cout

Read More

Display a percentage in Java

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

To display a percentage in Java, use the following DecimalFormat.DecimalFormat decFormat = new DecimalFormat("#%");Since, we have used the DecimalFormat class, therefore do not forget to import the following package −import java.text.DecimalFormat;Now, let us learn how to display percentage −decFormat.format(0.80) decFormat.format(-0.19) decFormat.format(1.88)The above will be displayed as −80% -19% 188%The following is the complete example −Exampleimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("#%"); System.out.println(decFormat.format(0.80)); System.out.println(decFormat.format(-0.19)); ...

Read More

Java Program to convert byte[] array to String

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

To convert byte[] to String, firstly let us declare and initialize a byte array.// byte array byte[] arr = new byte[] {78, 79, 33};Now take a String and include the array in it.String str = new String(arr);Let us see the complete example to convert byte array to String.Examplepublic class Demo {    public static void main(String args[]) {       // byte array       byte[] arr = new byte[] {78, 79, 33};       String str = new String(arr);       // string       System.out.println("String = "+str);    } }OutputString = NO!

Read More

Convert LinkedList to ArrayList in Java

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

A LinkedList can be converted into an ArrayList by creating an ArrayList such that the parameterized constructor of the ArrayList initialises it with the elements of the LinkedList.A program that demonstrates this is given as follows −Exampleimport java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class Demo {    public static void main(String[] args) {       LinkedList l = new LinkedList();       l.add("Orange");       l.add("Apple");       l.add("Peach");       l.add("Guava");       l.add("Pear");       List aList = new ArrayList(l);       System.out.println("The ArrayList elements are: ");     for ...

Read More

DecimalFormat("###E0") in Java

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

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Exampleimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("###E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88)); ...

Read More

SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z') in Java

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

Using the SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”), wherein E is for Day of Week −// displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime()));Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Exampleimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { ...

Read More

C++ Program to find size of int, float, double and char in Your System

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

Data Types in C++There are many data types in C++ but the most frequently used are int, float, double and char. Some details about these data types are as follows −int - This is used for integer data types which normally require 4 bytes of memory space.float - This is used for storing single precision floating point values or decimal values. float variables normally require 4 bytes of memory space.double - This is used for storing double precision floating point values or decimal values. Double variables normally require 8 bytes of memory space.char - This is used for storing characters. ...

Read More
Showing 691–700 of 1,421 articles
« Prev 1 68 69 70 71 72 143 Next »
Advertisements