String.format("%010d", 25);
0代表前面要补的字符
10代表字符串长度
d表示参数为整数类型
String s = "Hello World!";
int i = 13 ;
double d = 88.8 ;
System.out.printf("整形数据i = %2$+-10d \n字符串 s = %1$s \n浮点数据 d = %3$3.2f", s , i , d);
System.out.printf("\n不足10为用0来补:%10d" , i);
九九乘法表
- for (int i = 1; i < 10 ; i++) {
- for (int j = 1 ; j <= i ; j++) {
- System.out.printf("%1$3d * %2$-3d= %3$-3d\t" , j ,i , i * j);
- }
- System.out.println();
- }
输出时间
System.out.printf("当前时间:%1$TY-%1$Tm-%1$Td %1$TH:%1$TM:%1$TS" , new Date());