java格式化输出方法

 

##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

 

posted @ 2018-09-27 21:43  风之巍巍  阅读(1006)  评论(0编辑  收藏  举报