用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 红包祝福语简短10字
18 周六早晨祝福语简短