// Illustrate Java numeric datatypes. public class Datatypes { public static void main(String[] args) { // Range of a byte variable is 0 to 255. // Size of a byte variable is 1 byte. byte a = (byte) 127; // Range of a short variable is -32768 to 32767. // Size of a short variable is 2 bytes. short b = (short) 20000; // Range of an int variable is -2 billion to // 2 billion. Size is 4 bytes. int c = 1500000000; // Range of a long variable is -9 quintillion // to 9 quintillion. Size is 8 bytes. // Use L suffix to denote a long constant. long d = 6000000000L; // Display variables defined so far. System.out.println("a = " + a + " b = " + b + " c = " + c + " d = " + d); System.out.printf("a = %d b = %d c = %d d = %d\n", a, b, c, d); // Range of a float variable is between // -3.4*10^38 to 3.4*10^38. A float // variable has about 7 significant digits. // Use F suffix to denote a float constant. float f = 3.14159265358979323F; // Range of a double variable is between // -1.8*10^308 to 1.8*10^308. A double // variable has about 15 significant digits. double g = 3.14159265358979323; // Print remaining output. System.out.println("f = " + f + " g = " + g); System.out.printf("f = %f g = %f\n", f, g); } } // Output: a = 127 b=20000 c = 150000000000 d = 6000000000 a = 127 b=20000 c = 150000000000 d = 6000000000 f = 3.1415927 g = 3.141592653589793 f = 3.141593 g = 3.141593