# Different way of thinking about Leap

John Peters

Greenhorn

Posts: 18

posted 7 years ago

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:

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

Posts: 9065

12

posted 7 years ago

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

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