If b*c
is large, j
will eventually equal 2147418112
65536
(=216) and j*j
will be 0
(remember, Java ints
are always 32-bits). Performing %
when the divisor is 0
results in your ArithmeticException
. Note that any multiple of 65536
will cause this error. The 2147418112
(=231-216) originally referenced above is just the largest multiple that will fit in an int
.
Example code (you can run it yourself at http://ideone.com/iiKloY):
public class Main
{
public static void main(String []args)
{
// show that all multiples of 65536 yeild 0 when squared
for(int j = Integer.MIN_VALUE; j <= Integer.MAX_VALUE - 65536; j += 65536)
{
if((j*j) != 0)
{
System.out.println(j + "^2 != 0");
}
}
System.out.println("Done!");
}
}