JAVA 请定义一个2行3列的int类型的数组,其值为{{1,2,3},{2,4,6}}并将其每个元素全部显示

2024-12-02 07:56:18
推荐回答(3个)
回答1:

int[][] a=new int[][]{{1,2,3},{2,4,6}};
for(int i=0,il=a.length;i for(int j=0,jl=a[i].length;j System.out.print(a[i][j]+" ");
}
System.out.println();
}

回答2:

int a[][] = new int[2][3];
a[0] = new int[]{1,2,3};
a[1] = new int[]{2,4,6};

for(int x[] : a){
for(int n : x){
System.out.print(n+" ");
}
}

回答3:

int [][] arr=new int[][] {{1,2,3},{2,4,6}};
for(int i=0;i
for(int j=0;j System.out.print(arr[i][j]+",");
}
}