编写程序,判断给定的某个年份是否是闰年。

时间:2015-01-29 19:25:09   收藏:0   阅读:296

编写程序,判断给定的某个年份是否是闰年。       
闰年的判断规则如下: 
(1)若某个年份能被4整除但不能被100整除,则是闰年。       
(2)若某个年份能被400整除,则也是闰年。

解决方法:

import java.util.*;
public class Bissextile{
    public static void main(String[]arge){
        System.out.println("please input the nian:");
    int year;
    Scanner scanner = new Scanner(System.in);
    year = scanner.nextInt();
    if(year<0||year>3000){
        System.out.println("the Year is wrong,exit!");
        System.exit(0);
    }
    if((year%4==0)&&(year%100!=0)||(year%400==0))
        System.out.println(year+"is bissextile");
    else
        System.out.println(year+"is not bissextile");
    }    
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!