首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java printf格式札记

2013-08-16 
java printf格式笔记import org.junit.Testpublic class TestMe {@Testpublic void test() throws IOExce

java printf格式笔记

import org.junit.Test;public class TestMe {@Testpublic void test() throws IOException {// 占位符指定使用哪个参数填充值System.out.printf("%2$s %2$s %1$s \n", "111", "222");// 111 111 222// 浮点数保留小数点后尾数(四舍五入取整)System.out.printf("%.2f \n", 1.256F);// 1.23// 千分位分割输出整型System.out.printf("%,d \n", 12345678);// 12,345,678// 默认右对齐System.out.printf("%12d| %15d|  \n", 12345678, 666666666);// 左对齐,不足补空格System.out.printf("%-12d| %-15d|   \n", 12345678, 666666666);System.out.println();// '%%'输出百分号%%System.out.printf("%d%% \n", 58);// 不足位补零System.out.printf("%05d \n", 98);// 00058// 负数将添加括号System.out.printf("%(d \n", -98);// (98)System.out.printf("%tF  \n", System.currentTimeMillis());// 14:28:07System.out.printf("%tT  \n", System.currentTimeMillis());// 2013-08-15}}

?

参考:http://java.chinaitlab.com/base/835591.html?

?

?

--end

?

?

热点排行