To format a string, use the format method. javase

1. Code

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

2. Results display

  45.56    14AB  

Process finished with exit code 0


Guess you like

Origin blog.csdn.net/weixin_42768634/article/details/113778863