Java中的Sprintf等效项

纸马:

Printf在1.5版本中添加到Java中,但是我似乎找不到如何将输出发送到字符串而不是文件的方法(这是sprintf在C语言中的作用)。有谁知道如何做到这一点?

横田Eugene:
// Store the formatted string in 'result'
String result = String.format("%4d", i * j);

// Write the result to standard output
System.out.println( result );

查看格式及其语法

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章