我们知道输出格式化数字可以使用printf()和format()方法。String类使用静态方法format()返回一个String对象而不是PrintStream对象。
String类的静态方法format()能用来创建可复用的格式化字符串,而不仅仅是用于一次打印输出。如下所示:
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);
|
你也可以这样写
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);
上一篇:java入门教程:连接字符串
一级建造师二级建造师消防工程师造价工程师土建职称房地产经纪人公路检测工程师建筑八大员注册建筑师二级造价师监理工程师咨询工程师房地产估价师 城乡规划师结构工程师岩土工程师安全工程师设备监理师环境影响评价土地登记代理公路造价师公路监理师化工工程师暖通工程师给排水工程师计量工程师
执业药师执业医师卫生资格考试卫生高级职称护士资格证初级护师主管护师住院医师临床执业医师临床助理医师中医执业医师中医助理医师中西医医师中西医助理口腔执业医师口腔助理医师公共卫生医师公卫助理医师实践技能内科主治医师外科主治医师中医内科主治儿科主治医师妇产科医师西药士/师中药士/师临床检验技师临床医学理论中医理论