「java闰年编程」java中闰年算法

博主:adminadmin 2022-11-26 01:45:10 117

今天给各位分享java闰年编程的知识,其中也会对java中闰年算法进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

编写java程序判断闰年。

代码如下:

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

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

用Java程序判断是否是闰年

以下为代码:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class LeapyearTest extends Applet implements ActionListener{

Label lblResult;

Button btn;

TextField txt;

int year;

boolean leap;

public void init() {

lblResult=new Label("请输入要判断的年份");

txt=new TextField(5);

btn=new Button("判断");

add(lblResult);

add(txt);

add(btn);

btn.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

year=Integer.parseInt(txt.getText());

if(year%4==0;;(year%100)!=0)

{leap=true;

}

else if(year%400==0){

leap=false;

}

if(leap==true)

lblResult.setText(year+"年是闰年");

else

lblResult.setText(year+"年是平年");

txt.setText("");

}

}

扩展资料:

在windows下编译java文件、执行:

1、先创建一个txt,更改为test.java。

2、编写代码,为输出为holloword。

3、找到cmd,并进行打开cmd。

4、编译java文件,输入命令为javac test.java。

5、如果没有报错,查看当前目录下是否有class文件产生。

6、执行class文件,在命令输入java test,输出为holloword。

java闰年问题

public

class

Birthday

{

int

year;

int

month;

int

day;

public

Birthday(int

y,

int

m,

int

d)

{

//

括号内逗号,写成了分号

year

=

y;

month

=

m;

day

=

d;

}

public

void

isLeapYear()

{//

这行同上

//

boolean

leapyear=int

a=year/4(int

b=year/100int

c=year/400);

boolean

leapyear

=

false;

if

(this.year

%

100

==

this.year

%

400

==

0)

{

leapyear

=

true;

}

else

if

(this.year

%

4

==

0)

{

leapyear

=

true;

}

System.out.println("您所输入的年份是闰年吗?"

+

leapyear);

}

public

static

void

main(String[]

args)

{

Birthday

Bri1

=

new

Birthday(2000,

10,

7);//

整型写成了字符串

Bri1.isLeapYear();

}

}

程序错误挺多的,我给改了改,不知道还是不是你的原意~~

java闰年

月和月中间连接符号不能用,这是并且的关系,要有||或者的关系。

求java编程,判断某年分是否是闰年,输出为ture或false。

按照你的要求编写的判断某年分是否是闰年的java程序如下

import java.util.Scanner;

public class A {

 public static void main(String[] args) {

  Scanner sc=new Scanner(System.in);

  int year=sc.nextInt();

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

   System.out.println("true");

  }else{

   System.out.println("false");

  } 

 }

}

运行结果

输入 2017

输出 false

用 Java 编写一个程序,判断2000—2050年之间哪些年是闰年?

其实就是看2000~2050能被4整除的数,代码为:

public class Main {

public static void main(String[] args) {

System.out.println("2000~2050年之间的闰年有:");

for (int i = 2000; i = 2050; i++) {

if (i % 4 == 0) {

System.out.print(i + " ");

}

}

}

}

运行结果:

关于java闰年编程和java中闰年算法的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-26,除非注明,否则均为首码项目网原创文章,转载请注明出处。