Posted by: sajhauser September 28, 2006
Java Help
Login in to Rate this Post:     0       ?        
you haven't applied the dang logic behind the definition! you have made assumption as if there are only 2 condition, when, infact there are 3..so you have to first check by 4. the definition first tells you to check with 4, right? // Is theYear Divisible by 4? if (theYear % 4 == 0) { // Is theYear Divisible by 4 but not 100? if (theYear % 100 != 0) { System.out.println(theYear + " is a leap year."); } // Is theYear Divisible by 4 and 100 and 400? else if (theYear % 400 == 0) { System.out.println(theYear + " is a leap year."); } // It is Divisible by 4 and 100 but not 400! else { System.out.println(theYear + " is not a leap year."); } } // It is not divisible by 4. else { System.out.println(theYear + " is not a leap year."); }
Read Full Discussion Thread for this article