0
点赞
收藏
分享

微信扫一扫

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 条评论