Michael Wilkes
Michael Wilkes

Reputation: 35

Java weird out of bounds?

I have no idea why I'm getting out of bounds for this.

int[][] board = new int[3][3];
for (int i = 0; i < 3; i ++) {
    for(int j = 0; j < 3; i ++) {
        board[i][j] = 0;
    }
}

Upvotes: 1

Views: 58

Answers (1)

rgettman
rgettman

Reputation: 178303

You are incrementing i in the j for loop. Change

for(int j = 0; j < 3; i ++){

to

for(int j = 0; j < 3; j++){

Upvotes: 5

Related Questions