![](/img/trans.png)
[英]How i can println the statuscode in display with a toast when the request is fail?
[英]Java println formatting so I can display a table?
如何以允許我將輸出格式化為表格的方式利用System.out.print(ln/f)
?
如果我要使用printf
,我應該指定哪種格式來實現以下結果?
示例表我想要打印:
n result1 result2 time1 time2
-----------------------------------------------------
5 1000.00 20000.0 1000ms 1250ms
5 1000.00 20000.0 1000ms 1250ms
5 1000.00 20000.0 1000ms 1250ms
一切都排好了漂亮嗎?
是的,從Java 5開始,用於System.out
的PrintStream
類具有printf
方法,因此您可以使用字符串格式。
更新:
實際的格式化命令取決於您要打印的數據,您想要的確切間距等。以下是許多可能的示例之一:
System.out.printf("%1s %-7s %-7s %-6s %-6s%n", "n", "result1", "result2", "time1", "time2");
System.out.printf("%1d %7.2f %7.1f %4dms %4dms%n", 5, 1000F, 20000F, 1000, 1250);
System.out.printf("%1d %7.2f %7.1f %4dms %4dms%n", 6, 300F, 700F, 200, 950);
你可以println("\\t")
打印一個標簽,它會很容易地對齊一切。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.