2011-11-11 11 views
0
System.out.printf("%7s", "a"); 
    System.out.printf("%7s", "b"); 
    System.out.printf("%7s", "c"); 
    System.out.printf("%7s", "d"); 

只想給字符串7個空格。沒有4個新的printf(),有沒有更好的方法打印?簡化printf

+0

你到底想幹什麼? –

+0

試着循環給它。 – Ram

+0

爲什麼不''System.out.print(「a b c d」)'? –

回答

10
System.out.printf("%7s%7s%7s%7s", "a", "b", "c", "d"); 
3

您正在打印... d

char first = 'a'; 
    char second = first + 1; // will be b 

所以你可以使用一個for循環和避免重複