怎样用JAVA写判断一个年份是不是闰年的程序

怎样用JAVA写判断一个年份是不是闰年的程序,第1张

/

/

/

@author qingsongwang

/

import javautil;

public class B {

public static boolean isRun(int year)

{

return (year % 4 != 0 )|| (year % 100 == 0 )&& (year % 400 != 0);

}

public static void main(String[] args) {

Scanner input=new Scanner(Systemin);

int year;

Systemoutprintf("你输入的年份是:%s", year=inputnextInt());

if(isRun(year)){

Systemoutprint("(是闰年)");

}

else{

Systemoutprint("(不是闰年)");

}

}

}

直接运行这个程序即可!

import javautil;

public class Judge {

/

@param args

/

public static void main(String[] args) {

Scanner input = new Scanner(Systemin);

Systemoutprint("输入年份:");

int Num = inputnextInt();

int Y = Num%4;

if ( Y == 0 ) {

Systemoutprintln(+ Num +"份为闰年");

}else{

Systemoutprintln(Num+"份为平年");

}

}

}

这是我当年学java的时候找到资料。

public class Bissextile {

public static void main(String[] args) {

Bissextile instance = new Bissextile();

while (!instanceisBissextile()) {

Systemoutprintln("不是闰年\n");

}

Systemoutprintln("是闰年");

}

private boolean isBissextile() {

Systemoutprintln("请输入年份:");

Scanner scanner = new Scanner(Systemin);

int year = scannernextInt();

return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

}

}

以上就是关于怎样用JAVA写判断一个年份是不是闰年的程序全部的内容,包括:怎样用JAVA写判断一个年份是不是闰年的程序、java中用来判断平年闰年的代码怎么写、用java程序判断输入年份是否为闰年,如果输入错误,能重新输入,知道输入正确为止等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9587032.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存