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

Steve Jensen

Ranch Hand

Posts: 126

posted 13 years ago

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/

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/

John Bonham was stronger, but Keith Moon was faster.

Barry Gaunt

Ranch Hand

Posts: 7729

posted 13 years ago

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

"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

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch

Getting someone to think and try something out is much more useful than just telling them the answer.

Marilyn de Queiroz

Sheriff

Posts: 9063

12

posted 13 years ago

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

Except every year that is evenly divisible by 400.

This means that if a year is divided by 400, for example, 2000/400 = 5

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.

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.

JavaBeginnersFaq

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt

Marilyn de Queiroz

Sheriff

Posts: 9063

12

posted 13 years ago

Do you still have questions about this, Steve?

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt