概述
可快速计算某年是否是闰年,因为可以知道了二月有多少天
Java代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str = sc.nextLine(); int year = Integer.parseInt(str.split(" ")[0]); int mouth = Integer.parseInt(str.split(" ")[1]); Calendar calendar=Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, mouth-1); int lastDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println(lastDay); } }
|
结果
2008 2
29