尝试正确打印这个语句,有点复杂,因为我需要一个“|”在我的二维数组中的一列被打印出来之后立即。
System.out.println(toprow);
System.out.println(botrow);
System.out.println(line2);
for(row=0;row<22;row++)
{
System.out.printf("%02d%s ", row,"|");
for(col=0;col<32;col++)
System.out.printf("%s",mapicons[row][col]);
System.out.printf("%s", "|");
System.out.println();
}
这是打印出来的内容:
| 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3|
| 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2|
|----------------------------------------------------------------|
00| |
01| |
02| * |
03| |
04| * |
05| |
06| |
07| * |
08| # |
09| |
10| * |
11| |
12| |
13| |
14| * |
15| * |
16| |
17| |
18| * |
19| |
20| |
21| |
不知道如何排列“|”在最后。如果我将它添加到 col for 语句中的第一个 printf 语句中,它将打印一个“|”对于每一列。所以我不确定如何消除两个打印语句之间自动占用的空间。
最佳答案
在打印每行的左侧时,您似乎有一个无关的空格字符:
// v-- here
System.out.printf("%02d%s ", row,"|");
删除它;其他一切看起来都打印得很好。
System.out.printf("%02d%s", row,"|");
关于java - 正确设置打印格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19736719/