String.format System.out.printf的用法-简单

其实我的需求很简单,就是向字符串里面传递几个变量。解决方法是使用静态方法String.format ,网上搜的解释看的人头晕,一堆参数比如这个(http://blueram.javaeye.com/blog/441683)。

后来找到官方文档(http://download.oracle.com/javase/tutorial/java/data/strings.html) 找到了简单的答案,搞了这么长时间Java居然没有上过官网,汗一个记下J2SE官网 (http://download.oracle.com/javase/) 还是老外写的简单,我喜欢。

翻译一下是这样的:使用String.format方法可以让你构建一个可格式化的字符串,而不是一次输出的那种。例子如下,一看就懂。

String fs;

fs = String.format("The value of the float variable is %f, while the value of the " + "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);

System.out.println(fs);

如果是打印的话还可以这样。

System.out.printf("The value of the float variable is %f, while the value of the " + "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值