2
我們可以使用空格填充輸出以適應java中使用printf的「固定寬度列」。例如:帶有重複週期的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
夠公平的..所以答案是否定的,否則不能寫我自己的代碼。好吧。 –
但是,請正確使用它,因爲您的字裏面有空格 – ObieMD5