java 判断是否是闰年

时间:2020-02-23 14:35:06  来源:igfitidea点击:

在本教程中,我们将看到如何检查闰年。

import java.util.Scanner;
 
public class LeapYearFinder
{
    public static void main(String args[])
    {
       int year;
       Scanner scanner = new Scanner(System.in);
	   
       System.out.print("Enter Year : ");
       year = scanner.nextInt();
	   
       if((year%4 == 0) && (year%100!=0)){
           System.out.print(year+" is a Leap Year");
       }else if(year%100 == 0){
           System.out.print(year+" is not a Leap Year");
       }else if(year%400 == 0){
           System.out.print(year+" is a Leap Year");
       }else{
           System.out.print(year+" is not a Leap Year");
       }
    }
}

输出:

Enter Year : 2016
2016 is not a Leap Year