# Leap Year Problem !

teeyes prakash

Greenhorn

Posts: 19

posted 15 years ago

I have started doing Leap year Assignment..I hv just finsihed the code bu the only thing Iam not able to understand is thebelow thing :

"

except every year that is evenly divisible by 100

except every year that is evenly divisible by 400.

"

What does this mean literally. I have consulted many but none seems to give me a satisfied reply..

Plz plz give me a hint on what the above is..

I hv figured out that I must use Boolean logic but something stops me.

A nice clue will surely of great help...

Rgds

Teeyes

"

except every year that is evenly divisible by 100

except every year that is evenly divisible by 400.

"

What does this mean literally. I have consulted many but none seems to give me a satisfied reply..

Plz plz give me a hint on what the above is..

I hv figured out that I must use Boolean logic but something stops me.

A nice clue will surely of great help...

Rgds

Teeyes

Marilyn de Queiroz

Sheriff

Posts: 9065

12

posted 15 years ago

There is a clue in the style guide that might help clarify this for you.

If the year is evenly divisible by 400, it is a leap year

If the year is evenly divisible by 100, it is not a leap year (unless it is also evenly divisible by 400)

If the year is evenly divisible by 4, it is a leap year (unless it is also evenly divisible by 100 - in which case it is not a leap year)

If the year is evenly divisible by 400, it is a leap year

If the year is evenly divisible by 100, it is not a leap year (unless it is also evenly divisible by 400)

If the year is evenly divisible by 4, it is a leap year (unless it is also evenly divisible by 100 - in which case it is not a leap year)

JavaBeginnersFaq

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

Joel Cochran

Ranch Hand

Posts: 301

posted 15 years ago

Unless it is ALSO evenly divisible by 400! (not to confuse things... )

------------------

Joel Cochran

Originally posted by Marilyn deQueiroz:

If the year is evenly divisible by 4, it is a leap year (unless it is also evenly divisible by 100 - in which case it is not a leap year)

Unless it is ALSO evenly divisible by 400! (not to confuse things... )

------------------

Joel Cochran

Wait a minute, I'm trying to think of something clever to say...<p>Joel

teeyes prakash

Greenhorn

Posts: 19

bill bozeman

Ranch Hand

Posts: 1070

Richard Boren

Ranch Hand

Posts: 233

posted 15 years ago

Teeyes, I feel Marilyn's explanation is clear. You need to read it critically and look at the Style Guide for the clue she told you about.

Anyway here's my go at it:

it's a leap year if -

evenly divisible by 400

-OR-

evenly divisible by 4 and

it's

Hope this helps.

Anyway here's my go at it:

it's a leap year if -

evenly divisible by 400

-OR-

evenly divisible by 4 and

**NOT**evenly divisible by 100.it's

**NOT**a leap year if - evenly divisible by 4 and evenly divisible by 100.Hope this helps.

Amber Woods

Ranch Hand

Posts: 111

posted 15 years ago

Maybe this will help:

First of all if the year is divisible by 4 then it may likely be a leap year but if it is not divisable by 4 then you automatically know it is not a leap year.

Lets just say that it is divisible by 4 now you have to find out if that year is divisible by 100. If that year is divisible by 100 then it is not a leap year, but you have to do one more check on that same year if you have made it to this point (yr is div by 4 AND year is div by 100). The next check would be if that year is divisible by 400, if that is true at this point then that year would finally be a leap year.

Here are some examples:

The year 2004 is divisible by 4 (making it a likely candidate for leap year but needs to be checked further), AND it is not divisible be 100 so now you can say that it is a leap without checking anything else.

The year 2000 is divisible by 4 (Now check further) AND is divisible divisible by 100 (this year now may not be a leap year but needs another check to decide whether it is or not), the final check the year 2000 needs to go through is that is if it is divisible by 400 (which is true finally making it a leap year)

The year 2100 is divisible by 4 (right now may be a leap year Check further), is divisible by 100 (right now is not a leap year, Check further), it is not divisible by 400 which means it is NOT a leap year.

The year 1999 is not divible by 4 so you don't even need to check further you know it is not a leap year.

Hope this helps. Sorry it is so verbose.

Amber Woods

First of all if the year is divisible by 4 then it may likely be a leap year but if it is not divisable by 4 then you automatically know it is not a leap year.

Lets just say that it is divisible by 4 now you have to find out if that year is divisible by 100. If that year is divisible by 100 then it is not a leap year, but you have to do one more check on that same year if you have made it to this point (yr is div by 4 AND year is div by 100). The next check would be if that year is divisible by 400, if that is true at this point then that year would finally be a leap year.

Here are some examples:

The year 2004 is divisible by 4 (making it a likely candidate for leap year but needs to be checked further), AND it is not divisible be 100 so now you can say that it is a leap without checking anything else.

The year 2000 is divisible by 4 (Now check further) AND is divisible divisible by 100 (this year now may not be a leap year but needs another check to decide whether it is or not), the final check the year 2000 needs to go through is that is if it is divisible by 400 (which is true finally making it a leap year)

The year 2100 is divisible by 4 (right now may be a leap year Check further), is divisible by 100 (right now is not a leap year, Check further), it is not divisible by 400 which means it is NOT a leap year.

The year 1999 is not divible by 4 so you don't even need to check further you know it is not a leap year.

Hope this helps. Sorry it is so verbose.

Amber Woods

"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown

teeyes prakash

Greenhorn

Posts: 19

bill bozeman

Ranch Hand

Posts: 1070

posted 15 years ago

No, you have to have the 100 part. For example, year 2000 is divisible by 100, so it wouldn't be a leap year, but it is also divisible by 400 so it is.

Now 2100 is divisible by 100, so it is not a leap year, and it is not divisible by 400, so it still isn't a leap year.

You have to do all 3 checks and you have to do them in order.

Check for 4

Check for 100

Check for 400

Bill

Now 2100 is divisible by 100, so it is not a leap year, and it is not divisible by 400, so it still isn't a leap year.

You have to do all 3 checks and you have to do them in order.

Check for 4

Check for 100

Check for 400

Bill

teeyes prakash

Greenhorn

Posts: 19

Matthew Phillips

Ranch Hand

Posts: 2676

posted 15 years ago

There are some years that are divisible by 4 and divisible by 100 but not divisible by 400. An example would be the year 200. If you did not check to see if it is divisible by 100 then you would determine that it is a leap year when it is not. 2100 is a good example as well. 2100 is evenly divisible by 4 putting it into the possibly leap year category. When tested against 100, it turns out that it is also evenly divisible there. The 100 test overrides the 4 test and takes it out of the possibly a leap year category. It is then tested against 400, which overrides 100. It is not evenly divisible by 400, so it is not a leap year. In the case of the year 2000, the 4 test puts it into the possibly leap year category. When tested against 100 it is taken out. When tested againt 400 it is determined that 2000 is a leap year. I hope this makes it clear.

Matthew Phillips

Matthew Phillips

Matthew Phillips

Marilyn de Queiroz

Sheriff

Posts: 9065

12

posted 15 years ago

Originally posted by teeyes prakash:

"Is this step ( checking for divisibility by 100) really necessary..???"

I suggest you write the program without this step and see what happens. You tell me, is this step really necessary???

"Is this step ( checking for divisibility by 100) really necessary..???"

I suggest you write the program without this step and see what happens. You tell me, is this step really necessary???

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

Arthur Lyman

Greenhorn

Posts: 11

posted 15 years ago

I will try give my concise version of the rule.

Every year is a leap year when it is evenyly divisible by 4, unless it is also divisble by 100. e.g., 1904 is a leap year; 1900 is not.

If the year is divisible by 400, it is a leap year NO MATTER WHAT. e.g., 2000 is a leap year because it is divisible by 400(This rule tales precedence over the divisibility by 100 rule).

Every year is a leap year when it is evenyly divisible by 4, unless it is also divisble by 100. e.g., 1904 is a leap year; 1900 is not.

If the year is divisible by 400, it is a leap year NO MATTER WHAT. e.g., 2000 is a leap year because it is divisible by 400(This rule tales precedence over the divisibility by 100 rule).

Arthur E. Lyman<BR>a_lyman@hotmail.com