public class Main {public static void main(String[] args) {int year = 2020; //直接打印数字System.out.println(year);System.out.println("----------------");//直接打印数字System.out.format("%d%n",year);//总长度是8,默认右对齐System.out.format("%8d%n",year);//总长度是8,左对齐System.out.format("%-8d%n",year);//总长度是8,不够补0System.out.format("%08d%n",year);//千位分隔符System.out.format("%,8d%n",year*10000);//保留5位小数System.out.format("%.5f%n",Math.PI);//不换行System.out.format("%.5f",Math.PI);System.out.println("----没有换行哟-----");}
}
输出:
2020
----------------
20202020
2020
00002020
20,200,000
3.14159
3.14159----没有换行哟-----