Java printf格式化以打印表或列中的项目 [英] Java printf formatting to print items in a table or columns

查看:59
本文介绍了Java printf格式化以打印表或列中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用printf在整洁的列中打印内容.

I am wanting to print things in a neat columns using 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);,但是它打印出了这个代码:

I have this code System.out.printf("%s %.6f %s \n", word, web.getFrequency(word), loc);, but it prints out this:

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 ("%-30s %1.7f %s%n", word, etc, etc2);

这篇关于Java printf格式化以打印表或列中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆