• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Leap Year

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to question the validity of this statement made about Assgn 1.3.
"The tricky thing here is that a leap year occurs:
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
except every year that is evenly divisible by 400. "
Wouldn't that mean that the year 2000 wasn't a leap year?
2000/4 = 500
2000/100 = 20
2000/400 = 5
Please set me straight if I am misinterpreting this pseudo code.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ryan
It's all in the reading...
divisible by 4 = leap year!
except divisible by 100 = not a leap year
except divisible by 400 = leap Year!
If you consider the two "excepts" as a double negative (i.e. if it's divisable by 100 but NOT divisible by 400) all within the "divisible by 4" group, being divisible by 400 would then be a leap year.
This still may be a bit confusing, but I can't think of a better way to say this....
Pat B.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If only there were an easy way to do grouping with parentheses in natural language...
x = year is divisible by 4
y = year is divisible by 100
z = year is divisible by 400
Year is a leap year = ( x && !y | | ( x && ( y && z ) ) )
A better way to term the requirement in natural language is : "A year is a leap year if it divisible by 4. If a year that is divisible by 4 is also divisible by 100, it is not a leap year. However, if a year is divisible by 4, 100, and 400, then it it a leap year."
By this assertion 2000 was a leap year...
HTH,
-Nate
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second except relates to the first, ie, if a year that is evenly divisible by 4 and is evenly divisible by 100 is also evenly divisible by 400 then it is a leap year.
So 2000 was a leap year but 1900 was not since 1900 is evenly divisible by 4 & 100 but not by 400.
John
 
Ryan Ryszka
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help and the quick response!!! I think I have it now.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also see an example/explanation in the Style Guide

[This message has been edited by Marilyn deQueiroz (edited January 18, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic