用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 婆婆高寿祝福语大全简短