遇到整百年时(如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 + " 是平年!");
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-10-30
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-09-21
  • 2021-11-28
  • 2021-10-04
相关资源
相似解决方案