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');
    }
}

 

相关文章:

  • 2021-08-16
  • 2021-05-29
  • 2021-06-07
  • 2021-08-15
  • 2021-06-17
  • 2022-12-23
猜你喜欢
  • 2021-06-25
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-05-25
相关资源
相似解决方案