[Java in NetBeans] Lesson 13. Multidimensional Arrays
阿新 • • 發佈:2018-12-20
這個課程的參考視訊和圖片來自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