Numeric Data Type Conversion


byte bVal = 127;
int iVal = 100;
System.out.println(bVal+iVal); // 127 + 100 = 227
System.out.println(10/4); // int/ int 2.5 => 2
System.out.println(10.0/4); // double / int => double divided by double => 2.5
System.out.println((char)0x12340041);
System.out.println((byte)(bVal+iVal)); // 127 + 100 => (byte)227 => 1110 0011 => 1 + 2 + 32 + 64 – 128 => -29
System.out.println((int)2.9 + 1.8); // 2 + 1.8 => 2.0 + 1.8 => 3.8
System.out.println((int)(2.9 + 1.8)); // (int)4.1 => 4
System.out.println((int)2.9 + (int)1.8); // 2 + 1 => 3