📜  闰年 java 方法 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:47.943000             🧑  作者: Mango

代码示例1
public class LeapYear {

    // Method to check leap year
    public static void checkLeapYear(int year) {
        if (year % 400 == 0) {
            System.out.println(year + " is a leap year.");
        } else if (year % 100 == 0) {
            System.out.println(year + " is not a leap year.");
        } else if (year % 4 == 0) {
            System.out.println(year + " is a leap year.");
        } else {
            System.out.println(year + " is not a leap year.");
        }

    }

    public static void main(String[] args) {
        // Examples
        checkLeapYear(1998);
        checkLeapYear(2000);
    }
}

Output:

1998 is not a leap year.
2000 is a leap year.