Advanced Leap Year in Java: Explanation & Practice

Determine leap year with century rule

Problem summary

Check if a year is a leap year using the complete rule: divisible by 4, except century years must be divisible by 400.

Starter code

public class Main {
    public static void main(String[] args) {
        int year = 2000; // Test case 1
        
        // Apply full leap year rules
        // Print: <year> is a leap year / <year> is not a leap year
    }
}

Expected output and test cases

  • 2000 % 400 = 0
    2000 is a leap year
  • Century not divisible by 400
    1900 is not a leap year
  • 2024 % 4 = 0
    2024 is a leap year

Hints

  1. Check divisibility by 400 first
  2. Then check if century (divisible by 100)
  3. Finally check divisibility by 4

Related Control Flow exercises

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