Ad space (banner)
โ˜•Java Lessons
Lesson 65 / 68

Checking Whether a Year Is a Leap Year

This lesson covers checking whether a year is a leap year in Java, so you understand how to write judgment logic that combines several conditions. It's for anyone searching "Java leap year check implementation."

A year is a leap year if it's divisible by 4, and not divisible by 100, or if it's divisible by 400. It's a basic piece of logic used a lot in calendar and date-calculation programs.

The example expresses this entire complex rule in a single expression: (year % 4 == 0 && year % 100 != 0) || year % 400 == 0. The year 2024 is divisible by 4 and not by 100, so it's a leap year; 1900 is divisible by 100 but not by 400, so it's not.

A common early mistake is judging leap years using only "a multiple of 4." The classic example: 2000 is a leap year because it's divisible by 400, while 1900 is a normal year because it's divisible by 100 but not 400.

In real projects, this leap-year check is essential for accurate day-count calculations when implementing calendar or date-calculation functionality.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Java directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)