Ways of Thinking About Problems Leap Year – After and including 1582, Evenly divisible by 4, except evenly divisible by 100, except evenly divisible by 400. Not leap year – Before 1582, Not evenly divisible by 4 and evenly divisible by 100 and not 400. All years Pre 1582 Post 1582 NOT % 4 == 0 % 100 == 0 % 400 == 0 IS NOT
All years Pre 1582 = and post 1582 NOT % 4 == 0 % 100 == 0 % 400 == 0 IS NOT if (year < 1582) “is not a leap year” else if (year % 400 == 0) “ is a leap year” else if (year % 100 == 0) “ is not a leap year” else if (year % 4 == 0) “ is a leap year else
All years Pre 1582 = and post 1582 NOT % 4 == 0 % 100 == 0 % 400 == 0 IS NOT if (year < 1582) “is not a leap year” else if (year % 4 != 0) else if (year % 400 == 0) “ is a leap year” else if (year % 100 == 0) “ is not a leap year” else “ is a leap year “ This variant seeks to eliminate most of the cases before we get down to the more specific leap year candidate cases.
There are many other solutions