我们可以使用空格来填充输出以适应 java 中使用 printf 的“固定宽度列”。例子:
System.out.printf("%-30s - %s%n", "hello hello", "goodbye goodbye");
System.out.printf("%-30s - %s%n", "lots of cats",
"large amounts of dogs");
System.out.printf("%-30s - %s%n", "a crowd of teachers", "no students");
System.out.printf("%-30s - %s%n", "three desks", "twenty boxes");
给出输出
hello hello - goodbye goodbye
lots of cats - large amounts of dogs
a crowd of teachers - no students
three desks - twenty boxes
我想要实现的是:
hello hello. . . . . . . . . . . goodbye goodbye
lots of cats . . . . . . . . . . large amounts of dogs
a crowd of teachers. . . . . . . no students
three desks. . . . . . . . . . . twenty boxes
或者
hello hello..................... goodbye goodbye
lots of cats.................... large amounts of dogs
a crowd of teachers............. no students
three desks..................... twenty boxes