Java输出格式 [英] Java output formatting
本文介绍了Java输出格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
看看 java.util.Formatter 。
String.format()提供了一个方便的包装。 ):
String s = String.format(e =%+ 10.4f,Math.E);
它超越了C的printf格式。例如,它支持一个可选的语言环境,格式符号可以通过显式索引而不是隐式与一个参数相关联。
编辑:固定上面的链接。
I was wondering if Java has some sort of class to help on output formatting. I know in C++, in iomanip, there is a method call setw. I was wondering if Java has something similar to this.
解决方案
Have a look at java.util.Formatter.
String.format() provides a convenient wrapper.
For example (modified from an example on the link):
String s = String.format("e = %+10.4f", Math.E);
It goes beyond C's ?printf formats. For example, it supports an optional locale, and format symbols can be associated with an argument by explicit index rather than implicit.
Edit: Fixed the link above.
这篇关于Java输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文