平年和闰年定义

遇到整百年时(如2000,1900,300)要被400整除才是闰年,否则为平年(2000闰年,1900平年,300平年);
遇到非整百年时(如2004,2005),只要被4整除就是闰年,不能被4整除为平年(2004闰年,2005平年)。
闰年的2月有29天,平年的2月有28天。

System.out.println("请输入年份:");
int year = scan.nextInt();

//判断闰年和平年
if ((year % 100 != 0 && year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)) {
System.out.println(year + " 是闰年!");
}else {
System.out.println(year + " 是平年!");
}

原文地址:https://www.cnblogs.com/weloglog888/p/5929103.html