[Java in NetBeans] Lesson 13. Multidimensional Arrays

时间:2023-03-08 21:32:55
[Java in NetBeans] Lesson 13. Multidimensional Arrays

这个课程的参考视频和图片来自youtube

主要学到的知识点有:

1. Multidimensional Array: Array that has more than one dimension.

  • Create a array with two dimensions.
char[][] board = new char[3][3];    // tic-tac-toe board
board[0][0] = 'X'; // place an X in upper-left
board[1][2] = 'O'; // place an O in row 1 col 2
board[2][0] = 'X'; // place an X in row 2 col 0
board[2][2] = 'O'; // place an O in row 2 col 0
board[1][1] = 'W'; // place an W in row 1 col 1 // Print the array
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
System.out.printf("[%d][%d]=%s ",i,j,board[i][j]);
}
} //The result is shown as below
[0][0]=X [0][1]= [0][2]=
[1][0]= [1][1]=W [1][2]=O
[2][0]=X [2][1]= [2][2]=O