Alright so basically, I have a multi-dimensional array, Board[8][8]. I'm trying to take random values within the array and make them a different value. The value that I am changing must already be a certain value. The code I am running keeps yeilding these results:
java.lang.ArrayIndexOutOfBoundsException: 8
at checkers.init(checkers.java:32)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
This is the code causing the problem. Note that line 8 is a variable declaration:
int BLACK = 1;
Random generator = new Random();
int checkersCount_B = 0, checkersCount_W = 0, x, y;
while(checkersCount_B < 9){
x = generator.nextInt(9);
y = generator.nextInt(9);
if(Board[x][y] == BLACK){
Board[x][y] = BLACK_CHECKER;
// System.out.println(x + " " + y);
checkersCount_B ++;
} else{
//nothing
}
}
Line 32 is the if statement.
The code works for a couple runs through the while loop, but never makes past two or three, any suggestions?