Write a JAVA program to display default value of all primitive data type of JAVA

java-programming

Here is a Java program to display the default value of all primitive data types:

java
public class DefaultValuesDemo {
    static boolean bool;
    static byte by;
    static short sh;
    static int in;
    static long l;
    static float f;
    static double d;
    static char c;

    public static void main(String[] args) {
        System.out.println("Default values of primitive data types:");
        System.out.println("Boolean: " + bool);
        System.out.println("Byte: " + by);
        System.out.println("Short: " + sh);
        System.out.println("Int: " + in);
        System.out.println("Long: " + l);
        System.out.println("Float: " + f);
        System.out.println("Double: " + d);
        System.out.println("Char: " + c);
    }
}
When you run this program, it will output the default values of all primitive data types:
Default values of primitive data types:
Boolean: false
Byte: 0
Short: 0
Int: 0
Long: 0
Float: 0.0
Double: 0.0
Char:

This program declares variables of each primitive data type and then prints their values, which will be the default values assigned by Java.

Next Post Previous Post
No Comment
Add Comment
comment url