判断是否是闰年

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

 * 
 * 
 */
public class YearDemo {
    public static void main(String[] args) {
        //1提示用户输入年数
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要判断的年数:");
        int year = sc.nextInt();
        
        /*判断是否是闰年
        判断规则:
            (1)若某个年份能被4整除但不能被100整除,则是闰年。
            (2)若某个年份能被400整除,则也是闰年。*/
        if((year%4==0 && year%100 !=0)||year%400==0){
            System.out.println(year+"年是闰年");
        }else{
            System.out.println(year+"年不是闰年");
        }
    }
}

 

posted @ 2017-04-11 21:23  皮皮虾我们上  阅读(9617)  评论(0编辑  收藏  举报