我使用了以下代码:
public static void ch5ex18c() {
System.out.println("Pattern C");
String num = "6 5 4 3 2 1";
for (int count = 10; count >= 0; count-=2){
System.out.printf("%-10s", num.substring(count, 11) + "\n");
}
}
我知道我可以使用if语句解决这个问题,但我不想这样做,我想知道它为什么会这样做。
答案 0 :(得分:0)
问题是你的新行是在额外空格(“1 \ n”+空格)之前插入的,你需要删除减号(左对齐)并进行一些小的数学修改。
1\n spaces (shown on next line to make it seem like your justifying right
2 1\n spaces
等等