// Ian! D. Allen - idallen@idallen.ca - www.idallen.com // FunnyMath3 - wrong answers from simple arithmetic // Compile and run this program. // Explain why some of the outputs are incorrect. public class FunnyMath3 { public static void main(String[] args) { System.out.println("Add 0.1 from 0.1 to 0.5"); for (double d = 0.1; d <= 0.5; d += 0.1){ System.out.println(d); } System.out.println(""); System.out.println("Add 0.1 from 1.1 to 1.5"); for (double d = 1.1; d <= 1.5; d += 0.1){ System.out.println(d); } } } /* OUTPUT Add 0.1 from 0.1 to 0.5 0.1 0.2 0.30000000000000004 0.4 0.5 Add 0.1 from 1.1 to 1.5 1.1 1.2000000000000002 1.3000000000000003 1.4000000000000004 */