Java - Why does int default to 0 when a value outside the range is attempted to be stored in it : <p>I have a simple program for calculating the x to the power of y.</p>

<pre><code>    public static int calculatePower(int x, int y) {

    int result = 1;

    if (y == 0)
        return result;
    for (int i = 1; i &lt;= y; i++) {

        result = result * x;
    }

    return result;
}
</code></pre>

<p>When i pass the parameters as 4 and 15, i get the value back as 1073741824. But when the parameters are 4 and 16, the value returned is zero. </p>

<p>If the outer range value cannot be stored in int, shouldnt it be retaining the last value - 1073741824 ?</p>
