Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LeapYearChecker {
- public static void main(String[] args) {
- // Create a Scanner object to read input from the user
- Scanner scanner = new Scanner(System.in);
- // Prompt the user to enter a year
- System.out.print("Enter a year: ");
- // Read the year from the user
- int year = scanner.nextInt();
- // Close the Scanner
- scanner.close();
- // Check if the year is a leap year
- boolean isLeapYear = false;
- if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
- isLeapYear = true;
- }
- // Display the result
- if (isLeapYear) {
- System.out.println(year + " is a leap year.");
- } else {
- System.out.println(year + " is not a leap year.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement