在Java中,定义二维数组的方式有以下几种:
int[][] arr = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] arr = new int[3][3];
arr[0] = new int[]{1, 2, 3};
arr[1] = new int[]{4, 5, 6};
arr[2] = new int[]{7, 8, 9};
int[][] arr = new int[3][3];
int[][] arr = new int[3][3];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = i * arr.length + j + 1;
}
}
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: Java中怎么声明一个变量