You're using the wrong limit in the inner loop; you should be using the length of a row, not the number of columns. (Since your two-dimensional array doesn't have the same number of rows and columns, this is especially noticeable.)
Because of this, you're going off the end of the first row of the array when you try to access the 4th element. Your code specifies a maximum value for the column index of ticBoard.length
(i.e. 4), which does not correspond to the actual number of items in that row (i.e. 3).
This can be fixed by looping up to the number of elements in the row (i.e. ticBoard[d].length
), not the number of rows in the array (i.e. ticBoard.length
)
Furthermore, you're incrementing the wrong value in the inner loop; it should be r
, not d
.
for(int d = 0; d < ticBoard.length; d++) {
for(int r = 0; r < ticBoard[d].length; r++) {
System.out.print(ticBoard[d][r]);
}
System.out.println(); // So that each new row gets its own line
}