哪个先考虑?[col][row]还是[row][col]?
public class multiDiArray {
public static void main(String[] args) {
char [][] name = {
{'A','B','C','D','Q'},
{'E','F','G','H','R'},
{'I','J','K','L','S'},
{'M','N','O','P','T'},
{'U','V','W','X','Y'}
};
System.out.println(name[1][0]); // shows J
/*System.out.println(name[0][0]); // shows A
System.out.println(name[3][1]); // shows N
System.out.println(name[3][1]); // shows N
System.out.println(name[0][0]); // shows A
System.out.println(name[3][4]); // shows T
System.out.println(name[2][0]); // shows I
System.out.println(name[3][1]); // shows N
*/
}
}
(行)(col)是正确的顺序,所以[0][0]= A [1] [0] = E [0] [1] = B
0 {'A','B','C','D','Q'},
1 {'E','F','G','H','R'},
2 {'I','J','K','L','S'},
3 {'M','N','O','P','T'},
4 {'U','V','W','X','Y'}
0 1 2 3 4
我希望这就是你要找的
java默认多维数组为arrays[column][row].
你甚至可以在代码中使用顺序
例如,您想先打印行再打印列。