我试图向右缩进输出2个空格,是否可以使用.format而不是做2个空格?
System.out.format(" %-15s %7.2f %5.0f %-20s\n", getName(), payPerHour, hours, task.getTask());
^ //2 spaces in front
答案 0 :(得分:1)
是的,它是
System.out.format("%2s%-15s %7.2f %5.0f %-20s\n", " ", getName(), payPerHour, hours, task.getTask());