# Operators......Using them in the Leap Year Assignment

Steve Jensen
Ranch Hand
Posts: 126
I'm doing the Java-3 (Leap) assignment, and the algorithm to sort out when a year is a leap year, or not, is doing my head in.
OK, breaking it down............
A year is a leap year when:-
It is evenly divisible by 4 - OK no problem
Except every year that is evenly divisible by 100.

Are we therefore saying that the year 1900 is NOT a leap year because 1900/100 = 19. And the number 19 is not evenly divisible? As 1900/400 = 4.75 - NOT an even number, so the failing criteria is the '100 rule'?
Except every year that is evenly divisible by 400.

Does this mean that if a year is divided by 400, for example, 2000/400 = 5, as the answer is NOT an even number, that this meets the criterion of what does constitute a leap year?
1600 is a leap year, and so is 2000. Yet they do not meet the same criterion, i.e., the both meet the '100' rule, but not the '400' rule.
I am confused, big time.
I am testing my leap years using this little applet:- http://www.cs.trincoll.edu/cpsc115/labs/ch5.leapyear/

Barry Gaunt
Ranch Hand
Posts: 7729
Hi Steve,
"evenly divisible" means "is divisible by"; that is,
not leaving a remainder.
For example 21 is evenly divisible by 7. 20 is not because dividing 20 by 7 leaves a remainder of 6.
That's the direction you have to head in.
Have FUN as they say...
-Barry

Marilyn de Queiroz
Sheriff
Posts: 9065
12
A year is a leap year when:-

It is evenly divisible by 4 - OK no problem

Example: the year 504 is evenly divisible by 4.

Except every year that is evenly divisible by 100.

We are therefore saying that the year 1900 is NOT a leap year because 1900/100 = 19 with no remainder or fractional part, so the failing criteria is the '100 rule'?

Except every year that is evenly divisible by 400.

This means that if a year is divided by 400, for example, 2000/400 = 5 with no remainder or fractional part, that this meets the criterion of what does constitute a leap year?

For example 2001/400 = 5 remainder 1. Therefore it does not satisfy the "400 rule".

1600 is evenly divisible by 400 with no remainder and is a leap year, and so is 2000.

Marilyn de Queiroz
Sheriff
Posts: 9065
12