##Java中实现格式化输出的几种方式:
1、System.out.printf();
类似于c语言的printf方法。如:

int x = 55;

System.out.format(“x = %5x”, x);

输出结果为:x = 37

2、System.out.format()
int x = 55;

System.out.printf(“x = %5c”, x);

输出结果为:x = 7

3、String.format()
String提供的静态方法。

int x = 55;

System.out.println(String.format(“x = %5x”, x));

输出结果为:x = 37

4、Formatter
int x = 55;

Formatter format = new Formatter(System.out);

format.format(“x = %5x”, x);

输出结果为:x = 37


本文来自 wanna_wsl 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/wanna_wsl/article/details/62237955?utm_source=copy

 

相关文章:

  • 2021-10-25
  • 2021-04-13
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-09-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-09-09
相关资源
相似解决方案