Java 判断是否为闰年

题目描述

公历闰年四年一闰;百年不闰,四百年再闰。如1980、1904年是4的倍数,因此它是闰年;1900年是百年的倍数,它不是闰年;2000年虽然是百年的倍数,但同时又是400年的倍数,所有它是闰年。下面的程序给出一个年份,判断它是不是闰年。请按提示在空格中填入正确的内容。程序如下:

public class Main{
    public static void main(String[] args)
	{	
		int year;//定义year表示年份
		__(1)__;//定义isLeapYear表示是否是闰年,true(是),false(不是)
		
		__(2)__;//将year赋值为1980
		isLeapYear=__(3)__;//根据year计算出isLearYear的值
		System.out.println(year+"是闰年:" + isLeapYear);//输出
		
		year=1900;//以下计算1900年是否是闰年
		isLeapYear=__(4)__;//此处同__(3)__
		System.out.println(year+"是闰年:" + isLeapYear);
		
		year=2000;//以下计算2000年是否是闰年
		isLeapYear=__(5)__;//此处同__(3)__和__(4)__
		System.out.println(year+"是闰年:" + isLeapYear);
	}
}
输入描述
输出描述
见样例输出,最后一行行末有换行
输出样例
1980是闰年:true
1900是闰年:false
2000是闰年:true
程序代码
public class Main{
    public static void main(String[] args){	// 主方法
		int year; // 定义year表示年份
		boolean isLeapYear; // 定义isLeapYear表示是否是闰年,true(是),false(不是)
		
		year = 1980; // 将year赋值为1980
		isLeapYear = (year % 4 == 0 & year % 100 != 0) | year % 400 == 0 ? true : false; // 根据year计算出isLearYear的值
		System.out.println(year + "是闰年:" + isLeapYear); // 输出
		
		year = 1900; // 以下计算1900年是否是闰年
		isLeapYear = (year % 4 == 0 & year % 100 != 0) | year % 400 == 0 ? true : false; // 此处同__(3)__
		System.out.println(year + "是闰年:" + isLeapYear);
		
		year = 2000; // 以下计算2000年是否是闰年
		isLeapYear = (year % 4 == 0 & year % 100 != 0) | year % 400 == 0 ? true : false; // 此处同__(3)__和__(4)__
		System.out.println(year + "是闰年:" + isLeapYear);
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值