2016-10-22 40 views
-2
System.out.println(tree.item +"\t\t\t"+tree.list); 
as   [26, 27, 38] 
associated   [1] 
at   [17, 18] 
attack  [10] 

但我想打印這樣是System.out.print的java格式式樣

as   [26, 27, 38] 
associated [1] 
at   [17, 18] 
attack  [10] 
+0

歡迎堆棧溢出!請[參觀],環顧四周,並仔細閱讀[幫助],尤其是[*我如何提出一個好問題?](/ help/how-to-ask) –

+0

顯示一些研究。閱讀文檔。提示:https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#printf-java.lang.String-java.lang.Object...- – Axel

回答

0

我沒有要訪問代碼,但我可以建議使用- 這意味着基本上留下了縮進

例子:

String[] item = new String[] { "Audi", "BMW", "VW", "Ferrari", "Cherry QQ" }; 
float[] price = new float[] { 18000.0f, 24000.0f, 2100.50f, 786400.1f, 120.70f }; 

for (int i = 0; i < price.length; i++) { 
    System.out.printf("%2d. %-10s €%.2f\n", i + 1, item[i], price[i]); 
} 

結果將目光左對齊像

enter image description here

+0

非常感謝你。我很歡迎你解決問題 – user6388837

+0

! :) –