Basic question on Java's int
<p>Why does the below code prints 2147483647, the actual value being 2147483648? </p>

<pre><code>    i = (int)Math.pow(2,31) ;
    System.out.println(i);
</code></pre>

<p>I understand that the max positive value that a int can hold is 2147483647. Then why does a code like this auto wraps to the negative side and prints -2147483648?</p>

<pre><code>i = (int)Math.pow(2,31) +1 ;
System.out.println(i);
</code></pre>

<p>i is of type Integer. If the second code sample (addition of two integers) can wrap to the negative side if the result goes out of the positive range,why can't the first sample wrap?
Also ,</p>

<pre><code>i = 2147483648 +1 ;
System.out.println(i);
</code></pre>

<p>which is very similar to the second code sample throws compile error saying the first literal is out of integer range?
My question is , as per the second code sample why can't the first and third sample auto wrap to the other side?</p>
