【发布时间】:2021-06-22 16:57:26
【问题描述】:
我不知道你是否理解我,但我做了一个 3D 数组,其中每个“矩阵”具有相同的行但不同的列:
int nMatrix = 3, rows = 5;
String[][][] matrix = new String[nMatrix][][];
matrix[0] = new String[rows][r.nextInt(3) + 5];
matrix[1] = new String[rows][r.nextInt(3) + 5];
matrix[2] = new String[rows][r.nextInt(3) + 5];
我希望我可以同时打印这个:
// 5x5 matrix
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
// 5x7 matrix
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
// 5x6 matrix
[ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ]
有可能做这样的事情吗?
【问题讨论】:
标签: java arrays matrix multidimensional-array