2014-11-09 52 views
1

我需要第一可變Java的String格式具有不同的變量類型

2 spaces_go_here 300 batch ordered (due on day 7) 

此之後把例如5個空格的行是行的格式,它由一個整數+整數+字符串

我試過以下,但沒有成功。

System.out.printf("%-5d%d%s",i + " " + testProduct.getQuantity() + " batch"); 

雖然printf("%-5s%s",..作品,如果我試圖把空間在兩個字符串

回答

3

的參數之間的Variadic functionPrintStream.printf(String, Object...)用逗號分隔,這

System.out.printf("%-5d%d%s",i + " " + testProduct.getQuantity() + " batch"); 

應該是這樣的

System.out.printf("%-5d%d%s",i, testProduct.getQuantity()," batch"); 

System.out.printf("%-5d%d batch",i, testProduct.getQuantity()); 
+1

啊,確實有效。下次我應該只是RTFM。謝謝。 – RnD 2014-11-09 02:53:57

相關問題