This Java program determines whether a given year is a leap year or not. The user inputs a year, and the program evaluates it using the standard leap year conditions.
- Accepts a year as user input.
- Checks whether the year is a leap year based on:
- Divisibility by 4.
- Not divisible by 100, unless also divisible by 400.
- Displays whether the year is a leap year or not.
Main.javaβ Contains the implementation for the leap year checker.
- Compile the Java file:
javac Main.java
- Run the program:
java Main
- Enter a year when prompted:
Enter year: 2024 - Example Output:
This is a leap yearEnter year: 2023 This is not a leap year
- The user enters a year.
- The program checks if:
- The year is divisible by 4 but not by 100 (unless also divisible by 400).
- If the condition is met, it prints βThis is a leap yearβ.
- Otherwise, it prints βThis is not a leap yearβ.
This project is open-source and free to use.