Java精确计算闰年

闰年366天(2月中多一天),闰年2月29天
普通闰年:公历年份是4的倍数的,且不是100的倍数,为普通闰年。(如2004年就是闰年)
世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年(如1900年不是世纪闰年,2000年是世纪闰年)

import java.util.Scanner;
public class LeapYear {
    public static void main(String[] args) {    
        Scanner input = new Scanner(System.in);
        System.out.print("输入年份:");
        int year = input.nextInt();
         
        if((year % 4 == 0 && year % 100 != 0) || (year%400==0 && year % 3200 != 0) || year % 172800 == 0)
            System.out.print(year + "年是闰年");
        else 
            System.out.print(year + "年不是闰年");
    }
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注