【发布时间】:2015-11-01 19:55:50
【问题描述】:
我想使用 printf 将内容打印在整齐的列中。
happening 0.083333 [4]
hi 0.083333 [0]
if 0.083333 [8]
important 0.083333 [7]
is 0.250000 [3, 5, 10]
it 0.166667 [6, 9]
tagged 0.083333 [11]
there 0.083333 [1]
what 0.083333 [2]
我有这个代码System.out.printf("%s %.6f %s \n", word, web.getFrequency(word), loc);,但它会打印出这个:
happening 0.083333 [ 4 ]
hi 0.083333 [ 0 ]
if 0.083333 [ 8 ]
important 0.083333 [ 7 ]
is 0.250000 [ 3 5 10 ]
it 0.166667 [ 6 9 ]
tagged 0.083333 [ 11 ]
there 0.083333 [ 1 ]
what 0.083333 [ 2 ]
任何帮助将不胜感激。
【问题讨论】:
-
将线条填充到指定宽度:stackoverflow.com/questions/388461/…
-
可能重复:stackoverflow.com/questions/699878/… 建议使用宽度和精度说明符,设置为相同的值(例如 System.out.printf("%-30.30s %-30.30s%n" , v1, v2);)。另请参阅:docs.oracle.com/javase/7/docs/api/java/util/…
-
我不了解 java,但在 C 中这需要
\t
标签: java printf multiple-columns