二维数组根据其下标,判断它是第几个元素【i * col + j】

发布时间 2023-10-27 16:51:38作者: 爱新觉罗LQ

二维数组根据其下标,判断它是第几个元素

3 3
0 2 2
1 2 1
2 2 1

public class qqqq {
    static int row;
    static int col;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        row = in.nextInt();
        col = in.nextInt();
        int[][] arr = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.println("这是第 " + (i * col + j) + "个元素");
                arr[i][j] = in.nextInt();
            }
        }
    }
}