📜  Java |数组|问题5

📅  最后修改于: 2021-06-28 21:16:07             🧑  作者: Mango

public class Main {
    public static void main(String args[]) {
        int arr[][] = new int[4][];
        arr[0] = new int[1];
        arr[1] = new int[2];
        arr[2] = new int[3];
        arr[3] = new int[4];
   
        int i, j, k = 0;
        for (i = 0; i < 4; i++) {
            for (j = 0; j < i + 1; j++) {
                arr[i][j] = k;
                k++;
            }
        }
        for (i = 0; i < 4; i++) {
            for (j = 0; j < i + 1; j++) {
                System.out.print(" " + arr[i][j]);
                k++;
            }
            System.out.println();
        }
    }
} 

(A)编译器错误
(B)

0
 1 2
 3 4 5
 6 7 8 9 

(C)

0
 0 0
 0 0 0
 0 0 0 0 

(D)

9
 7 8
 4 5 6
 0 1 2 3 

答案: (B)
说明:在Java,我们可以创建锯齿状的数组。有关详细信息,请参见Java的锯齿状数组。
这个问题的测验