• String.format


     String str=null;  

    •     str=String.format("Hi,%s", "王力");  
    •     System.out.println(str);  
    •     str=String.format("Hi,%s:%s.%s", "王南","王力","王张");            
    •     System.out.println(str);                           
    •     System.out.printf("字母a的大写是:%c %n", 'A');  
    •     System.out.printf("3>7的结果是:%b %n", 3>7);  
    •     System.out.printf("100的一半是:%d %n", 100/2);  
    •     System.out.printf("100的16进制数是:%x %n", 100);  
    •     System.out.printf("100的8进制数是:%o %n", 100);  
    •     System.out.printf("50元的书打8.5折扣是:%f 元%n", 50*0.85);  
    •     System.out.printf("上面价格的16进制数是:%a %n", 50*0.85);  
    •     System.out.printf("上面价格的指数表示:%e %n", 50*0.85);  
    •     System.out.printf("上面价格的指数和浮点数结果的长度较短的是:%g %n", 50*0.85);  
    •     System.out.printf("上面的折扣是%d%% %n", 85);  
    •     System.out.printf("字母A的散列码是:%h %n", 'A');  

    结果:

        Hi,王力  

    • Hi,王南:王力.王张  
    • 字母a的大写是:A   
    • 3>7的结果是:false   
    • 100的一半是:50   
    • 100的16进制数是:64   
    • 100的8进制数是:144   
    • 50元的书打8.5折扣是:42.500000 元  
    • 上面价格的16进制数是:0x1.54p5   
    • 上面价格的指数表示:4.250000e+01   
    • 上面价格的指数和浮点数结果的长度较短的是:42.5000   
    • 上面的折扣是85%   
    • 字母A的散列码是:41  
  • 相关阅读:
    Android--多线程之Handler
    Android--Service之基础
    Android--UI之Fragment
    Android--多线程之图文混排
    python常用模块
    python应用之socket编程
    网络编程socket理论一
    pycharm Launching unittests with arguments
    python字符串格式化
    python数据类型之三
  • 原文地址:https://www.cnblogs.com/12344321hh/p/8128390.html
Copyright © 2020-2023  润新知