华南俳烁实业有限公司

考試首頁 | 考試用書 | 培訓(xùn)課程 | 模擬考場 | 考試論壇  
全國  |             |          |          |          |          |         
  當(dāng)前位置:計(jì)算機(jī)等級 > 二級考試 > Java語言程序設(shè)計(jì) > 考試輔導(dǎo) > 文章內(nèi)容
  

全國計(jì)算機(jī)等級考試Java語言程序設(shè)計(jì)輔導(dǎo)(39)

中華IT學(xué)院   【 】  [ 2016年2月11日 ]

我們知道輸出格式化數(shù)字可以使用printf()和format()方法。String類使用靜態(tài)方法format()返回一個(gè)String對象而不是PrintStream對象。

String類的靜態(tài)方法format()能用來創(chuàng)建可復(fù)用的格式化字符串,而不僅僅是用于一次打印輸出。如下所示:

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);
分享到:
本文糾錯(cuò)】【告訴好友】【打印此文】【返回頂部
將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動訪問考試網(wǎng) | 復(fù)制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導(dǎo)航  考試論壇
Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved
田林县| 汽车| 河北区| 长汀县| 延安市| 安康市| 伊宁县| 潼关县| 固镇县| 彰化市| 吴旗县| 从化市| 章丘市| 佛学| 阿拉善盟| 镇坪县| 兴安盟| 澄迈县| 特克斯县| 新郑市| 上思县| 措勤县| 家居| 福鼎市| 阜阳市| 佛冈县| 台湾省| 四平市| 望奎县| 齐齐哈尔市| 开阳县| 东安县| 安徽省| 南平市| 云和县| 克东县| 巫山县| 东乌珠穆沁旗| 秦皇岛市| 古田县| 措美县|