Leap Year Check in Java: Explanation & Practice

Determine if a year is a leap year

Problem summary

Check if 2024 is a leap year using the proper rules (div by 4, unless div by 100 unless div by 400).

Starter code

public class Main {
    public static void main(String[] args) {
        int year = 2024;
        
        // Check leap year rules
        // Print: 2024 is a leap year: true/false
    }
}

Expected output and test cases

  • 2024 is a leap year
    2024 is a leap year: true

Hints

  1. Divisible by 4 is the first check
  2. If divisible by 100, must also be divisible by 400
  3. Use nested if statements or combine with && and ||

Related Control Flow exercises

Practice all Control Flow exercises · Run this idea in the Java compiler