JAVA编写

来源:百度知道 编辑:UC知道 时间:2024/06/14 03:20:06
3.判断某一年是否为闰年:LeapYear.java
示例如下:
1989isnotaleapyear.
2000isaleapyear.

2050 is not a leap year.
提示:闰年的条件是符合下面二者之一:①能被4整除,但不能被100整除;②能被400整除。

public static void main(String[] args) {
int year = 2050;
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
System.out.println(year+"is a not leap year");
}else{
System.out.println(year+"is a leap year");
}
}

//我想这样比较简单...
import java.util.*;

public class YearOption {

private static GregorianCalendar cal = new GregorianCalendar();

public static void print(int year) {
if(cal.isLeapYear(year)) {
System.out.println(year + " 是闰年!");
} else {
System.out.println(year + " 不是闰年!");
}
}

public static void main(String[] args) {
for(int i = 1600; i <= 1620; i ++){
YearOption.print(i);
}

}

}

public class LeapYear {
public static void main(String[] args) {
int year = 2050;
if(year % 4 == 0 && year % 100 != 0 || year