标签:
public class StringFormatDemo { public static void main(String[] args) { String str = null; str = String.format("Hi,\t %s", "王力"); System.out.println(str); str = String.format("Hi,\t %s:%s.%s", "王南", "王力", "王张"); System.out.println(str); System.out.printf("字母a的大写是:\t %c %n", ‘A‘); System.out.printf("3>7的结果是:\t %b %n", 3 > 7); System.out.printf("100的一半是:\t %d %n", 100 / 2); System.out.printf("100的16进制数是:\t %x %n", 100); System.out.printf("100的8进制数是:\t %o %n", 100); System.out.printf("50元的书打8.5折扣是:\t %f 元%n", 50 * 0.85); System.out.printf("上面价格的16进制数是:\t %a %n", 50 * 0.85); System.out.printf("上面价格的指数表示:\t %e %n", 50 * 0.85); System.out.printf("上面价格的指数和浮点数结果的长度较短的是:\t %g %n", 50 * 0.85); System.out.printf("上面的折扣是\t %d%% %n", 85); System.out.printf("字母A的散列码是:\t %h %n", ‘A‘); } }
标签:
原文地址:http://www.cnblogs.com/olmlo/p/4805570.html