1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| import java.util.Date;
public class Printf { public static void main(String[] args) { System.out.printf("%s", new Integer(1212)); System.out.printf("%s%n", "end line"); System.out.printf("%s = %s%n", "Name", "Zhangsan"); System.out.printf("%S = %s%n", "Name", "Zhangsan"); System.out.printf("%1$s = %3$s %2$s%n", "Name", "san", "Zhang"); System.out.printf("true = %b; false = ", true); System.out.printf("%b%n", false); Integer iObj = 342; System.out.printf("%d; %d; %d%n", -500, 2343L, iObj); System.out.printf("%o; %o; %o%n", -500, 2343L, iObj); System.out.printf("%x; %x; %x%n", -500, 2343L, iObj); System.out.printf("%X; %X; %X%n", -500, 2343L, iObj); Double dObj = 45.6d; System.out.printf("%e; %e; %e%n", -756.403f, 7464.232641d, dObj); System.out.printf("%E; %E; %E%n", -756.403f, 7464.232641d, dObj); System.out.printf("%f; %f; %f%n", -756.403f, 7464.232641d, dObj); System.out.printf("%.1f; %.3f; %f%n", -756.403f, 7464.232641d, dObj); Date date = new Date(); long dataL = date.getTime(); System.out.printf("%1$ty-%1$tm-%1$td; %2$ty-%2$tm-%2$td%n", date, dataL); System.out.printf("%1$tY-%1$tB-%1$td; %2$tY-%2$tb-%2$td%n", date, dataL); System.out.printf("%1$tD%n", date); System.out.printf("%1$tF%n", date); System.out.printf("%1$tH:%1$tM:%1$tS; %2$tI:%2$tM:%2$tS%n", date, dataL); System.out.printf("%1$tH:%1$tM:%1$tS %1$tL%n", date); System.out.printf("%1$tH:%1$tM:%1$tS %1$tL %1$tp%n", date); System.out.printf("%1$tR%n", date); System.out.printf("%1$tT%n", date); System.out.printf("%1$tr%n", date); System.out.printf("%1$tF %1$tA%n", date); System.out.printf("%1$tF %1$ta%n", date); System.out.printf("%1$tc%n", date); } }
|