Integer [][] x = {{1,2,3},{4},{5,6}};
像这样在标准输出中打印元素的最佳方法是什么?
1
2
3
4
5
6
我尝试过Arrays.deepToString(x),但没有输出我想要的内容
最佳答案
试试这个:
public class MyClass {
public static void main(String args[]) {
Integer [][] x = {{1,2,3},{4},{5,6}};
for(Integer[] y : x) {
for(Integer i : y) {
System.out.println(i);
}
}
}
}
输出:
1
2
3
4
5
6
关于java - 打印不同大小数组中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47717690/