File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes Operators......Using them in the Leap Year Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Operators......Using them in the Leap Year Assignment" Watch "Operators......Using them in the Leap Year Assignment" New topic
Author

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

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
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/


John Bonham was stronger, but Keith Moon was faster.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
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


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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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.


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

Joined: Jul 22, 2000
Posts: 9043
    
  10
Do you still have questions about this, Steve?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operators......Using them in the Leap Year Assignment
 
Similar Threads
Leap Year
Leap assignment question
Java-3 Leap Question
Assignment 1.3 - conflicting Specs.
Leap year problem explain pls??