1. 编写一个类的方法,判断某一年是否为闰年。闰年的条件是符合下面二者之一:能被 4 整除,但不能被 100 整除;能400 整除。
Java的输入用到java.util.Scanner;需先引入
import java.util.*;
public class IsALeapYear {
private int year;
public IsALeapYear(int year)
{
this.year = year;
}
public boolean judgeLeapYear(int y)
{
boolean res = false;
if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
res = true;
return res;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner x = new Scanner(System.in);
int i = x.nextInt();
IsALeapYear y = new IsALeapYear(i);
System.out.println(y.judgeLeapYear(i));
}
}