aspose file tools*
The moose likes Cattle Drive and the fly likes Different way of thinking about Leap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Different way of thinking about Leap" Watch "Different way of thinking about Leap" New topic
Author

Different way of thinking about Leap

John Peters
Greenhorn

Joined: May 25, 2007
Posts: 18
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.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Different way of thinking about Leap