[問題] 印出整齊格式
像下面程式碼列印出來的樣子
0和9沒有真的對齊
(PTT上看起來有對齊,但Eclipse上沒有)
-9 -9 0 0
0 0 0 -9
0 -9 0 -9
-9 -9 0 0
printf要怎麼改才能漂亮對齊
就彷彿0的前面有看不見的加號那樣
thank
程式碼:
class Data {
public void wall() {
int[][] grid = new int[][] {
{ -9, 0, 0, -9 },
{ -9, 0, -9, -9 },
{ 0, 0, 0, 0 }, { 0, -9, -9, 0 },
{ -9, 0, -9, 0 },
{ -9, 0, 0, 0 }, { 0, 0, -9, 0 } };
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 4; i++) {
System.out.printf("%2d" + " ",
grid[i][j]);
}
System.out.print("\n");
}
}
}
public class Wall {
public static void main(String[] args) {
// TODO Auto-generated method stub
Data data = new Data();
data.wall();
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.65.89.53
※ 文章網址: https://www.ptt.cc/bbs/java/M.1432664797.A.A34.html
→
05/27 02:40, , 1F
05/27 02:40, 1F
我有試過
看起來都不整齊
推
05/27 02:46, , 2F
05/27 02:46, 2F
→
05/27 03:15, , 3F
05/27 03:15, 3F
→
05/27 03:15, , 4F
05/27 03:15, 4F
推
05/27 03:17, , 5F
05/27 03:17, 5F
推
05/27 03:21, , 6F
05/27 03:21, 6F
推
05/27 03:21, , 7F
05/27 03:21, 7F
→
05/27 03:22, , 8F
05/27 03:22, 8F
推
05/27 03:26, , 9F
05/27 03:26, 9F
推
05/27 03:32, , 10F
05/27 03:32, 10F
→
05/27 03:32, , 11F
05/27 03:32, 11F
→
05/27 03:32, , 12F
05/27 03:32, 12F
→
05/27 03:34, , 13F
05/27 03:34, 13F
→
05/27 03:34, , 14F
05/27 03:34, 14F
→
05/27 03:35, , 15F
05/27 03:35, 15F
→
05/27 03:37, , 16F
05/27 03:37, 16F
→
05/27 03:39, , 17F
05/27 03:39, 17F
推
05/27 08:17, , 18F
05/27 08:17, 18F
→
05/27 08:18, , 19F
05/27 08:18, 19F
推
05/27 08:20, , 20F
05/27 08:20, 20F
推
05/27 09:21, , 21F
05/27 09:21, 21F
→
05/27 09:48, , 22F
05/27 09:48, 22F
→
05/27 11:55, , 23F
05/27 11:55, 23F
推
05/27 14:19, , 24F
05/27 14:19, 24F
→
05/27 14:19, , 25F
05/27 14:19, 25F
→
05/27 14:19, , 26F
05/27 14:19, 26F
→
05/27 23:47, , 27F
05/27 23:47, 27F
→
05/27 23:47, , 28F
05/27 23:47, 28F
我研究設定看看
※ 編輯: dharma (210.65.89.53), 05/28/2015 16:34:16
推
05/31 23:22, , 29F
05/31 23:22, 29F
java 近期熱門文章
PTT數位生活區 即時熱門文章