In this post, we will see how to check leap year.
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");
}
}
}
Output:
Enter Year : 2018
2018 is not a Leap Year
2018 is not a Leap Year
That’s all about Java program to check leap year.