I have a problem in the code below:
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone {
public static void main (String[] args) throws java.lang.Exception {
int[] map = new int[100 * 100];
System.out.println("Works : " + map[10 * 100 + 5]);
System.out.println("Works? : " + map[99 * 100 + 99]);
System.out.println("Works?! : " + map[20 * 100 + 100]);
//System.out.println("And this?? : " + map[99 * 100 + 100]);
}
}
As you can see the last line (the comment) doesn't work; it throws an ArrayIndexOutOfBoundsException.
But I dont get it; it should be in the array's bounds. The array's size is 100*100 so 99 * 100 + 100 = 100*100 so index 100*100 is in the array.
I've already fixed the problem; I would just like to know why I get an exception on the above line.
Link to code: http://ideone.com/ydgU9s
