我的代碼是這樣的:對準
// for loop for displaying multiple values
for (int index = 0; index < 5; index++) {
System.out.println("\t\t" + name[index] + "\t\t\t" + "$" + sales[index] + "\t\t\t" + "$" + comm[index] + " ");
}
這是電流輸出,但我想用同樣的間距
Sales and Commission
======================================================
Salesperson Sales Amount Commission
-----------------------------------------------------
u ujuhygtfd $89000 $8900.0
uh uh $87000 $8700.0
t t $65000 $5200.0
f f $54000 $4320.0
u r $43000 $2580.0
Total: 9 Data entries
顯示輸出如何顯示我的數據,如這個?
Sales and Commission
======================================================
Salesperson Sales Amount Commission
-----------------------------------------------------
u ujuhygtfd $89000 $8900.0
uh uh $87000 $8700.0
t t $65000 $5200.0
f f $54000 $4320.0
u r $43000 $2580.0
Total: 9 Data entries
通常添加語言標記會很有幫助。在這種情況下,我假設Java? – chancea
如果有更好的方法(可能有),我不會這樣做,但是你可以測試你的字符串的大小,例如所有Salesperson的字符串必須是10個字符長,所以如果你的字符串只有4你會添加6'空格' –
@ njzk2:當然,但它是一個確切的重複?另請參閱http://blog.stackoverflow.com/2010/11/dr-strangedupe-or-how-i-learned-to-stop-worrying-and-love-duplication/ –