// Ian! D. Allen - idallen@idallen.ca - www.idallen.com // FunnyMath0 - wrong answers from simple arithmetic // Compile and run this program. Look at the output. // Explain why some of the outputs are incorrect. // Do not change the declarations of the variables. public class FunnyMath0 { public static void main(String[] args) { int i; // do not change this declaration int j; // do not change this declaration int k; // do not change this declaration long ii; // do not change this declaration long jj; // do not change this declaration long kk; // do not change this declaration float f; // do not change this declaration float g; // do not change this declaration float h; // do not change this declaration double ff; // do not change this declaration double gg; // do not change this declaration double hh; // do not change this declaration int add; // do not change this declaration System.out.println("\n-------------------------------------------"); System.out.println("Fun with integers\n"); i = 1000000000; j = 200000000; k = i + j; System.out.println(i + " plus " + j + " is " + k); i = 2000000000; j = 200000000; k = i + j; System.out.println(i + " plus " + j + " is " + k); System.out.println("\n-------------------------------------------"); System.out.println("Fun with long integers\n"); ii = 7000000000000000000L; jj = 2000000000000000000L; kk = ii + jj; System.out.println(ii + " plus " + jj + " is " + kk); ii = 8000000000000000000L; jj = 2000000000000000000L; kk = ii + jj; System.out.println(ii + " plus " + jj + " is " + kk); System.out.println("\n-------------------------------------------"); System.out.println("Fun with single-precision floating-point\n"); add = 1; // change this to change the amount added f = 10000000.0F; g = f + add; System.out.println(f + " plus " + add + " is " + g); f = 20000000.0F; g = f + add; System.out.println(f + " plus " + add + " is " + g); System.out.println("\n-------------------------------------------"); System.out.println("Fun with double-precision floating-point\n"); add = 1; // change this to change the amount added ff = 1000000000000000.0; gg = ff + add; System.out.println(ff + " plus " + add + " is " + gg); ff = 10000000000000000.0; gg = ff + add; System.out.println(ff + " plus " + add + " is " + gg); } }