闰年的判断规则如下: (1)若某个年份能被4整除但不能被100整除,则是闰年。 (2)若某个年份能被400整除,则也是闰年。
程序如下: public static void main(String[] args){
int year=0;
System.out.println("Please input the year:");
Scanner in=new Scanner(System.in);
String temp=in.next();
if(!isNum(temp)){
System.out.println("the year you input is not valid");
}else{
year=Integer.parseInt(temp);
if(year<1980||year>2050){
System.out.println("the year you input is not in the scale");
System.exit(1);
}else if((year%4==0&&year%100!=0)||year%400==0){
System.out.println(year+" is a leap year");
}else{
System.out.println(year+" is not a leap year");
}
}
} |