用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
热门推荐
5 薛之谦祝福语简短
10 免费生日祝福语简短独特
11 员工对同事祝福语简短
12 发给女儿生日简短祝福语
13 祝福语勤奋大全简短英语
14 中班入学祝福语简短大全
15 猪年给老师祝福语简短
16 新婚祝福语简短句子
17 朋友药店开业祝福语简短
18 祝福语简短创意闺蜜