Difference between revisions of "Leap Year Problem"
Line 25: | Line 25: | ||
year = Integer.parseInt( input ); | year = Integer.parseInt( input ); | ||
− | //first, check if it's a leap year. For it to be a leap year, it needs to either be divisible by 4 and NOT by 100, or be divisible by 400 | + | //first, check if it's a leap year. For it to be a leap year, |
+ | //it needs to either be divisible by 4 and NOT by 100, or be divisible by 400 | ||
if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) | if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) | ||
JOptionPane.showMessageDialog( null, year + " is a leap year! :)", "Leap Year!", JOptionPane.INFORMATION_MESSAGE ); | JOptionPane.showMessageDialog( null, year + " is a leap year! :)", "Leap Year!", JOptionPane.INFORMATION_MESSAGE ); |
Revision as of 12:19, 1 April 2010
Back to the Program-A-Day homepage
ProblemWrite a short program that takes a year as input from the user, and then determines whether or not that particular year is (or was) a leap year. As a reminder, here is the criteria that dictates whether or not a year is a leap year: If the year is evenly divisible by 4, then the year is a leap year -- unless it is also divisible by 100, in which case it is not. An exception to this is if the year is divisible by 400, then it is still a leap year. Example: |
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionThe solution... | ||
Code |