title: Sudden infinite loop above certain input argument?
body: <p>While learning Java I'm redoing some of the Project Euler problems.
  This is about Problem 14 - Longest Collatz sequence: <a href="https://projecteuler.net/problem=14" rel="nofollow">https://projecteuler.net/problem=14</a></p>
  
  <p>My programm runs just fine for a lower <code>CEILING</code> like 1000, but when executed like posted it loops infinitely, I think? What goes wrong here?</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) {
          int tempMax = 0;
          final int CEILING = 1_000_000;
  
          for (int j = 1; j &lt; CEILING; ++j) {
              tempMax = Math.max(tempMax, collatzLength(j));
          }
          System.out.println(tempMax);
      }
  
      static int collatzLength(int n) { //computes length of collatz-sequence starting with n
              int temp = n;
  
              for (int length = 1; ; ++length) {
                  if (temp == 1) 
                      return length;
                  else if (temp % 2 == 0)
                      temp /= 2;
                  else
                      temp = temp * 3 + 1;
              }
      }
  }
  </code></pre>
  
  <p>Calling <code>System.out.println(collatzLength(1000000));</code> seperately works just fine so I think we can rule an error here out.</p>