import java.util.Scanner;
public class LeapYearChecker {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
System.out.println(year + " is a leap year.");
} else {
System.out.println(year + " is not a leap year.");
}
}
}
Enter a year: 2011
2011 is not a leap year.
Enter a year: 2016
2016 is a leap year.
Scanner
class. Then, we use an if
statement to check whether the year is a leap year or not.if
statement, and print the appropriate message to the console using System.out.println()
.