设有以下一维网格数据
int[] gridData=new int[]{
0,1,2,
3,4,5,
6,7,8
};
用以下方法存入二维数组,及访问对应元素
int row = 3; // 行数
int col = 3; // 列数
int[][] grid = new int[row][];
for (int i = 0; i < row; i++) {
grid[i] = new int[col];
for (int j = 0; j < col; j++) {
grid[i][j] = gridData[i * col + j];
}
}
标签:int,网格,grid,new,数据,col,row
From: https://www.cnblogs.com/kingBook/p/16595879.html