17 Aug Java Program to display the minimum and maximum value of primitive data types
Java Datatype has a range, i.e. represented by a minimum and maximum. Primitive Data Types include the byte, short, boolean, int, long, float, double and char type.
Following are the minimum and maximum value of primitive data types in Java:
- byte: An 8-bit signed two’s complement integer
Minimum Value: -128
Maximum Value: 127 - short: A 16-bit signed two’s complement integer
Minimum Value: -32768
Maximum Value: 32767 - int: A 32-bit signed two’s complement integer
Minimum Value: -2,147,483,648
Maximum Value: 2,147,483,647 - long: A 64-bit two’s complement integer
Minimum Value: -9,223,372,036,854,775,808
Maximum Value: 9,223,372,036,854,775,807 - char: A single 16-bit Unicode character.
Minimum Value: ‘\u0000’ (or 0)
Maximum value: ‘\uffff’ - float: A single-precision 32-bit IEEE 754 floating point
Minimum Value: 1.4E-45
Maximum Value: 3.4028235E38 - double: A double-precision 64-bit IEEE 754 floating point
Minimum Value: 4.9E-324
Maximum Value: 1.7976931348623157E308 - boolean: Possible values, TRUE and FALSE.
Let’s now see some examples to display the minimum and maximum value of primitive data types:
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class Example { public static void main(String[] args) { short a = 10; byte b = 5; System.out.println("Value of a = " + a); System.out.println("short type MAXIMUM Value = " + Short.MAX_VALUE); System.out.println("short type MINIMUM Value = " + Short.MIN_VALUE); System.out.println("\nValue of b = " + b); System.out.println("byte type MAXIMUM Value = " + Byte.MAX_VALUE); System.out.println("byte type MINIMUM Value = " + Byte.MIN_VALUE); } } |
Output
1 2 3 4 5 6 7 8 9 |
Value of a = 10 short type MAXIMUM Value = 32767 short type MINIMUM Value = -32768 Value of b = 5 byte type MAXIMUM Value = 127 byte type MINIMUM Value = -128 |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class Example { public static void main(String[] args) { float a = 3.99f; double b = 10.99d; long c = 878768768L; System.out.println("Value of a = " + a); System.out.println("float type MAXIMUM Value = " + Float.MAX_VALUE); System.out.println("float type MINIMUM Value = " + Float.MIN_VALUE); System.out.println("\nValue of b = " + b); System.out.println("double type MAXIMUM Value = " + Double.MAX_VALUE); System.out.println("double type MINIMUM Value = " + Double.MIN_VALUE); System.out.println("\nValue of c = " + c); System.out.println("long type MAXIMUM Value = " + Long.MAX_VALUE); System.out.println("long type MINIMUM Value = " + Long.MIN_VALUE); } } |
Output
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Value of a = 3.99 float type MAXIMUM Value = 3.4028235E38 float type MINIMUM Value = 1.4E-45 Value of b = 10.99 double type MAXIMUM Value = 1.7976931348623157E308 double type MINIMUM Value = 4.9E-324 Value of c = 878768768 long type MAXIMUM Value = 9223372036854775807 long type MINIMUM Value = -9223372036854775808 |
No Comments