使用printf进行多种格式 [英] using printf for multiple formats
本文介绍了使用printf进行多种格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于如何使用多种格式的printf的问题。我想要这样的东西,printf里面的所有东西都是均匀分布的:
I have a question on how to use printf for multiple formats. I want something like this, where everything inside printf is spaced out evenly:
i i i i i
这就是我使用printf的方式:
and this is how I used printf:
// display headers
System.out.printf("", "%15s", "%15s", "%15s", "%15s", "Car Type",
"Starting Miles", "Ending Miles", "Distance/Gallon",
"Gallons/Distance", "Miles/Gallon");
当我执行我的程序时,上面不会显示出来,我只是去这个:
when I executed my program, the above wouldn't show up at all, I just go this:
run:
Gas & Mileage Calculations
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BUILD SUCCESSFUL (total time: 0 seconds)
推荐答案
<只需连接格式:
Just concatenate the formats:
System.out.printf("%15s%15s%15s%15s", "header 1", "header 2", ...);
这篇关于使用printf进行多种格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文