programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# Different way of thinking about Leap

Greenhorn
Posts: 18
• Number of slices to send:
Optional 'thank-you' note:
For some reason I couldn't wrap my mind around how the leap years should be tested. After using three sheets of paper to write out how the logic would make sense, and using Wikipedia, I think I've come up with something that makes more sense in my mind. I hope it helps someone else:

In simple terms:

Where the program should terminate kept hanging me up.

Good help from Wikipedia:

...most years whose division by 4 equals an integer are leap years.
Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.

Sheriff
Posts: 9109
12
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by John Peters:
If the year is divisible by 400, than it's true and program should exit.
If the year is not divisible by 100 but IS (and) divisible by 4, than it's true and should exit.
Otherwise it's false and the program should exit.

I think I would change it just a little bit ...
If the year is divisible by 400, than it's true -- final answer
If the year is divisible by 4 but (and) is not divisible by 100, than it's true -- final answer
Otherwise it's false -- final answer

 Don't get me started about those stupid light bulbs.