import java.time.*
data class Year(val year: Int) {
val isLeap = LocalDate.of(year, Month.FEBRUARY, 28).plusDays(1).dayOfMonth == 29
}
This approach may be considered a "cheat" for this exercise.
By adding a day to February 28th for the year, you can see if the new day is the 29th or the 1st.
If it is the 29th, then the year is a leap year.
This is done by using the plusDays()
and getDayOfMonth()
methods of the LocalDate class.
23rd Oct 2024
·
Found it useful?