使用 Formatter 格式化 Java 输出
对于 Formatter,导入以下包 −
import java.util.Formatter;
现在创建 Formatter 对象 −
Formatter f1 = new Formatter();
现在,我们将使用 Formatter 格式化输出 −
f1.format("Rank and Percentage of %s = %d %f", "John", 2, 98.5);以下是一个示例 −
示例
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f1 = new Formatter();
Formatter f2 = new Formatter();
f1.format("Rank and Percentage of %s = %d %f", "John", 2, 98.5);
System.out.println(f1.toString());
f2.format("Rank and Percentage of %s %s = %d %f", "David", "Warner", 1, 80.8);
System.out.println(f2.toString());
}
}输出
Rank and Percentage of John = 2 98.500000 Rank and Percentage of David Warner = 1 80.800000
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP