Java小程序之判断输入年份是否是闰年

题目:用Java编写一个根据输入的年份来判断是否是闰年(年份可以被4整除且不能被100整除)
代码如下:
文件名:LeapYearJudgement.java

public class LeapYearJudgement {

        private final int DIVISIBLE_NUM=4;
        private final int INDIVISIBLE_NUM=100;

        public void judge(int year){
            if((year%DIVISIBLE_NUM==0)&&(year%INDIVISIBLE_NUM!=0)){
                System.out.println(year+"是闰年");
            }else{
                System.out.println(year+"不是闰年");
            }
        }
}

文件名:Test.java

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {

        LeapYearJudgement lyj=new LeapYearJudgement();
        Scanner sc=new Scanner(System.in);

        System.out.println("input year:");
        try{
            int year=sc.nextInt();
            lyj.judge(year);
        }catch(Exception e){
            System.out.println("wrong");
        }
        sc.close();
    }
}

初学Java,欢迎大家对错误批评指正,指点迷津

你可能感兴趣的:(java小程序)