title: java loop with Integer.MAX_VALUE
body: <p>I have stumble upon such strange code that i don't why??</p>
  
  <pre><code>public class CrazyTest {
  
      public static void main(String[] args) {
  
          long val = 0L;
          for (int i = 0; i &lt; Integer.MAX_VALUE; i++) {
              val = i;
          }
          System.out.println("val = "+val);
  
          int kk =Integer.MAX_VALUE;
          System.out.println("kk = "+kk);
  
          long val2 = 0L;
          for (int i = 0; i &lt; Integer.MAX_VALUE; i++) {
              val2 = i;
          }
          System.out.println("val2 = "+val2);
      }
  }
  </code></pre>
  
  <p>the strange 1 is "val = " will be various while you run at two times and the value is
  "val=493794", "val=675042" why?</p>
  
  <p>the strange 2 is why the "kk = 2147483647" and "val2=2147483645", why the gap value is 2, not 1?</p>
  
  <p>my env is [Mac OS 64bit 10.8.3], the eclipse is [Indigo] , and jdk is [JavaSE6 MacOS default]</p>