判断某一年是否为闰年[20171117练习]

来源:互联网 发布:网络延长器价格 编辑:程序博客网 时间:2024/05/27 19:25
package com.mingrisoft;
import java.util.Scanner;

public class Demo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个年份");
        long year;
        try{
            year=scan.nextLong();
            if(year%4==0&&year%100!=0||year%400==0){
                System.out.println(year+"是闰年!");
                
                
            }
            else{
                System.out.println(year+"不是闰年");
            }
        }
        catch(Exception e){
            System.out.println("您输入的不是有效的年份");
        }
    }

}