title: Java: Project Euler #14 wrong answer
body: <p>My code of <a href="http://projecteuler.net/problem=14" rel="nofollow">Problem 14</a> in Project Euler is giving a wrong answer and I can not see what is wrong. Here is my code</p>
  
  <pre><code>public static void main(String[] args) {
          long answer = 0;
          long longest = 0;
          for (long i = 0; i &lt; 1000000; i++) {
              long num = i;
              long counter = 1;
              while (num &gt; 1) {
                  if (num % 2 == 0) num /= 2;
                  else num = 3 * num + 1;
                  counter++;
              }
              if (counter &gt; answer) {
                  answer = i;
                  longest = counter;
              }
          }
          System.out.println(answer);
          System.out.println(longest);
      }
  </code></pre>