I apologize if this has been posted before, however I could not find anything specifically related to my problem.
I have a small bit of my code here, I have a 2D array with some information, and I loop through the rooms and columns as shown. This works, and everything is printed out, but I get this error at the end of the loop:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at Main.main(Main.java:14)
Here is my code:
public class Main {
public static void main(String[] args){
int data[][] = {{1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 0, 0}};
int x;
int y;
for(int i = 0; i < data.length; i++){
for(int j = 0; j < data[j].length; j++){
x = j * 16;
y = i * 16;
System.out.println(x + " " + y + " " + data[i][j]);
}
}
}
}
What is the issue here?