编写java程序判断闰年。

要求先使用布尔型变量编写,再用if语句编写。跪求!!!急急急急急!!!!!

代码如下:

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月)。

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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-06-27

/**
* 公司 深圳市海枫科技有限公司
* 创建时间 2018年6月4日
* 邮件 [email protected]
*/
布尔型变量编写
int year = 2018;
boolean b1 = year%4==0;
boolean b2 = year%100!=0;
boolean b3 = year %400==0;
if(b1&&b2||b3){
//是闰年
}else{
//不是闰年
}
用if语句编写
int year=2018;
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
//是闰年
}else{
//不是闰年
}
你要求还挺高的,还要求好几种方法 

下面是配图,在工具中代码以及运行的结果

第2个回答  2021-04-08
package chaper4;
import java.util.Scanner;
public class chaper56 {
public static void main (String[] arge){
Scanner input = new Scanner(System.in);
System.out.print("请输入年份:");
int a = input.nextInt();
printR(a);

}
public static void printR(int x){
if(x%4==0){
System.out.println(x+"为闰年");
}else{
System.out.println(x+"为平年");
}
}

}
第3个回答  2020-06-12
/**
* 四闰 百不闰 四百闰
* @author sx
*
*/
public class Demo_2 {
public static void main(String[] args) {
int year=2000;
if(year%400==0) {
System.out.println("闰年");
}else {
if(year%100==0) {
System.out.println("平年");
}else {
if(year%4==0) {
System.out.println("闰年");
}else {
System.out.println("平年");
}
}
}
}
}
第4个回答  2009-03-17
public class leap {

/**
* @param args
*/

public static void main(String[] args)
{
java.util.GregorianCalendar c = new java.util.GregorianCalendar();
int year = 2009;
if (c.isLeapYear(year))
{
System.out.println(year + " 是闰年");
}
}
}
相似回答