【发布时间】:2017-03-25 19:53:20
【问题描述】:
这是我写的代码
class Printsqu {
public static void main(String[] args) {
int[][] array = { { 1,5,9,13 }, { 2,6,10,14 }, { 3,7,11,15 },
{ 4,8,12,16 }, };
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print( array[i][j]);
}
System.out.println();
}
}
}
输出应该是
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
这个但是打印出来了
1593
261014
371115
481216
所以我在它们之间添加了 \t 但它跳跃太多了。
有没有办法解决这个问题?
有趣的是数字之间的间距不同
如果你们添加有关代码和解释的详细信息,我将不胜感激。
【问题讨论】:
-
数组的第一行包含 3 而不是 13。
{1, 5, 9, 13} -
使用这个 System.out.print(array[i][j] +" \t");
-
\t 在代码中跳转太多没用
-
@WJ 请检查我的答案。谢谢
-
@Omore 在我尝试你的时候出错了...