Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图将我的输出向右缩进 2 个空格,是否可以使用 .format 而不是 2 个空格来做到这一点?
System.out.format(" %-15s %7.2f %5.0f %-20s\n", getName(), payPerHour, hours, task.getTask()); ^ //2 spaces in front
是啊,就是
System.out.format("%2s%-15s %7.2f %5.0f %-20s\n", " ", getName(), payPerHour, hours, task.getTask());