package arrays;
public class test {
public static void main(String[] args) {
int[] a={10,20,30};
int[] b={40,50,60};
m1(a,b);
}
public static void m1(int[]... x){
for(int[] x1:x){
System.out.println(x1[0]);
}
}
试运行:
int[] a={10,20,30};
int[] b={40,50,60};
m1(a,b);
在这里,您在 m1 方法中传递数组数组
public static void m1(int[]... x){ //array of arrays, //[[10,20,30], [40,50,60]]
for(int[] x1:x){
System.out.println(x1[0]);
}
}
在第一次迭代中,在 for 循环中,x1 为 [10,20,30],其 x1[0] 为 10。同样在第二次迭代中,x1 为 [40,50,60], x1[0 ] 将打印 40。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句