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
|
public class PrintfTest { public static void main(String[] args) { System.out.printf("%s","你好\n"); System.out.printf("%S\n","aaaa");
System.out.printf("%5s","qwe\n"); System.out.printf("%-5s","qwe\n");
System.out.printf("%5.3s\n","qweaa"); System.out.printf("%-5.3s\n","qweaa");
System.out.printf("%1$s = %3$s %2$s\n","name","san","zhang");
System.out.printf("%d\n",5); System.out.printf("%2d\n",553); System.out.printf("%5d\n",553); System.out.printf("%-5d\n",553);
long a = 10034L; System.out.printf("%1d\n",a);
int b = 123; System.out.printf("%o\n",b); System.out.printf("%1o\n",b); System.out.printf("%31o\n",b);
System.out.printf("%x\n",b); System.out.printf("%1x\n",b); System.out.printf("%31x\n",b);
System.out.printf("%c\n",'d');
float e = 2.35555F; double h = 3.55555; System.out.printf("%f\n",e); System.out.printf("%f\n",h); System.out.printf("%4.3f\n",h); System.out.printf("%-4.3f\n",h);
double i = 1000; System.out.printf("%1.3e\n",i); } }
|