I have a 2d array and I want to check if its in increasing order.
here is a example of 2d array increasing order:
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14,
15, 16, 17, 18, 19,
20, 21, 22, 23, 24,
here is what I have so far.
public class test{
int a[][] = new int[5][5];
boolean inOrder = false;
// game loop
public void gameloop(){
//check if 2d array is increasing order
for (int r = 0; r < a.length; r++) {
for (int c = 0; c < a[0].length; c++) {
if(r != 5){ //make sure its not out of bond
if(a[r][c] < a[r+1][c]){
inOrder = true;
}else{
incOrder = false;
}
}
}
}
}
I get an error on line:
line: if(r != 5){
error: Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException: 5