public static void main(String[] args) {  
            int a = 8;
            String s = String.format("%04d", a);
            System.out.println(s);
}  

 

length代表的是格式化后字符串的总长度
d是个占位符,会被参数a所替换。
0是在arr转化为字符后,长度达不到length的时候,前面以0补足。

 

相关文章:

  • 2022-12-23
  • 2021-08-27
  • 2021-09-06
  • 2022-02-09
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
猜你喜欢
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-09-26
相关资源
相似解决方案