m1方法具有三维数组作为参数,同时打印b(对象引用)给出[[[[email protected]
这意味着a是三维数组,但在for循环(粗体)中a表现为2 -d阵列,若设为i写为INT X [] [] []:一个那么它是Java中的三维数组for循环
giving error " Type mismatch: cannot convert from element type int[][] to
int[][][]"
什么是此行为的原因吗?
public class Arr {
public static void main(String[] args) {
int[][][] aa2=new int[2][1][];
m1(aa2);
}
public static void m1(int[][][] b)
{
**for(int[][] x:b)**
System.out.println(b);
}
}
甲3D阵列有效地是二维数组的数组。因此,当你想迭代一个,那就是你会得到的。 –
在哪条线上有错误 – Nathan
如果要打印循环中使用的2D数组,只需将输出更改为'System.out.println(x)'。 – user3734782