使用Java System.out.format进行长格式格式化的不同方法
System.out.format在Java中用于格式化输出。在这里,让我们说以下是我们的长篇文章。
long val = 787890;
为了格式化,我们考虑了以下证明输出合理的内容。
System.out.format("%d%n", val);
System.out.format("%9d%n", val);
System.out.format("%+9d%n", val);
System.out.format("%08d%n", val);
System.out.format("%,9d%n", val);下面是显示输出差异的完整示例。
示例
import java.util.Locale;
public class Demo {
public static void main(String []args) {
long val = 787890;
System.out.format("%d%n", val);
System.out.format("%9d%n", val);
System.out.format("%+9d%n", val);
System.out.format("%08d%n", val);
System.out.format("%,9d%n", val);
}
}这是输出。您可以轻松注意到格式的差异。
输出结果
787890 787890 +787890 00787890 787,890
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短