title: Why does i = i + i give me 0?
body: <p>I have a simple program:</p>
  
  <pre><code>public class Mathz {
      static int i = 1;
      public static void main(String[] args) {    
          while (true){
              i = i + i;
              System.out.println(i);
          }
      }
  }
  </code></pre>
  
  <p>When I run this program, all I see is <code>0</code> for <code>i</code> in my output. I would have expected the first time round we would have <code>i = 1 + 1</code>, followed by <code>i = 2 + 2</code>, followed by <code>i = 4 + 4</code> etc.</p>
  
  <p>Is this due to the fact that as soon as we try to re-declare <code>i</code> on the left hand-side, its value gets reset to <code>0</code>?</p>
  
  <p>If anyone can point me into the finer details of this that would be great.</p>
  
  <p>Change the <code>int</code> to <code>long</code> and it seems to be printing numbers as expected. I'm surprised at how fast it hits the max 32-bit value!</p>