用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
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短