首页 > 代码库 > 平年和闰年定义
平年和闰年定义
遇到整百年时(如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 + " 是平年!");
}
平年和闰年定义
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。