tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了平年和闰年定义相关的知识,希望对你有一定的参考价值。
遇到整百年时(如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 + " 是平年!");
}
以上是关于平年和闰年定义的主要内容,如果未能解决你的问题,请参考以下文章