java方法调用计算闰年

Python014

java方法调用计算闰年,第1张

public static void main(String[] args) {

int year = 2016//年份

Calendar can = Calendar.getInstance()

can.set(Calendar.YEAR, year)

if(can.getActualMaximum(Calendar.DAY_OF_YEAR) == 365){

System.out.println("平年")

}else{

System.out.println("闰年")

}

}

最简单的方法,直接看这一年一共有多少天就行了。

代码如下:

public class RUN {

public static void main(String[] args) {

//布尔型判断

int year = 2000

boolean b1 = year%4==0

boolean b2 = year%100!=0

boolean b3 = year%400==0

if(b1&&b2||b3){

System.out.println("闰年")

}else{

System.out.println("不是闰年")

}

//用if语句判断

int year2=2018

if(year2 % 4 == 0 &&year2 % 100 != 0 || year2 % 400 == 0){

System.out.println("是闰年")

}else{

System.out.println("不是闰年")

}

}

}

代码截图: 扩展资料:

闰年是公历中的名词。闰年分为普通闰年和世纪闰年。

普通闰年:能被4整除但不能被100整除的年份为普通闰年。(如2004年就是闰年,1999年不是闰年);

世纪闰年:能被400整除的为世纪闰年。(如2000年是闰年,1900年不是闰年);

闰年(Leap Year)是为了弥补因人为历法规定造成的年度天数与地球实际公转周期的时间差而设立的。补上时间差的年份为闰年。闰年共有366天(1-12月分别为31天,29天,31天,30天,31天,30天,31天,31天,30天,31天,30天,31天)。

凡阳历中有闰日(二月为二十九日)的年;闰余(岁余置闰。阴历每年与回归年相比所差的时日);

注意闰年(公历中名词)和闰月(农历中名词)并没有直接的关联,公历中只分闰年和平年,平年有365天,而闰年有366天(2月中多一天);

平年中也可能有闰月(如2017年是平年,农历有闰月,闰6月)。

参考资料:百度百科-闰年