When I run this class the for loop seems to terminate early
class Test {
public static void main(String[] args) {
int result = 0;
int en
Its a known bug in Java 6. The JIT optimizes the loop incorrectly. I believe more recent versions of Java don't have this bug.
http://vanillajava.blogspot.co.uk/2011/05/when-jit-gets-it-wrong.html
Java 6 update 16 is just over two years old. I suggest you update to the latest version Java 6 update 25 if you can't update to Java 7.
BTW Java 6 will be End Of Free Support in a couple of months (Dec 2012)
You can work around the JVM bug by using Integer.MAX_VALUE-1.