Check Leap Year

This program checks if a year is a leap year using multiple conditions.

Problem Statement

Write a Java program that checks if a year is a leap year.

Source Code

1 public class LeapYear {
2 public static void main(String[] args) {
3 int year = 2024;
4 if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
5 System.out.println(year + " is a leap year - Eduinq");
6 } else {
7 System.out.println(year + " is not a leap year - Eduinq");
8 }
9 }
10 }

Program Output

2024 is a leap year - Eduinq

Explanation

Leap year rules are: divisible by 400 leap year; divisible by 4 but not by 100 leap year; otherwise not. - The program uses logical OR and AND operators to combine these conditions. - This ensures accuracy across centuries. - For example, 2000 is leap (divisible by 400), 1900 is not (divisible by 100 but not 400), and 2024 is leap (divisible by 4 but not 100). Conclusion: Demonstrates multiple condition checks using logical operators.

Quick Links to Explore