格式化字符串,使用format方法。javase

一.代码

package com.zhuo.base;

public class Demo00 {
    
    
    public static void main(String[] args) {
    
    
        String str = String.format("%7.2f%6d%-4s", 45.556, 14, "AB");
        System.out.println(str.toString());
    }
}

二.结果显示

  45.56    14AB  

Process finished with exit code 0


猜你喜欢

转载自blog.csdn.net/weixin_42768634/article/details/113778863
今日推荐