for loop terminating early when comparing to Integer.MAX_VALUE and using System.out.println
问题 When I run this class the for loop seems to terminate early class Test { public static void main(String[] args) { int result = 0; int end = Integer.MAX_VALUE; int i; for (i = 1; i <= end; i += 2) { System.out.println(i); } System.out.println("End:" + i); } } Output is: 1 3 5 ... 31173 31175 End:31177 Why does it end there? Interestingly if I removed the System.out.println(i) in the for loop, the output would be End:-2147483647 . Obviously the value in i has wrapped round . The Java version I