使用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 婚前女儿生日祝福语简短