This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Long/Short ways
Posted by Kishori Sharan on February 12, 2002 at 9:22 PM
int year = 800 ; // Short way if ( ( year % 4 == 0 && year % 100 != 0 ) || ( year % 4 == 0 && year % 400 == 0 ) ) { System.out.println ( year + " is a leap year......." ) ; } else { System.out.println ( year + " is not a leap year......." ) ; } // Long way if ( year % 4 == 0 ) { if ( year % 100 == 0 ) { if ( year % 400 == 0) { System.out.println ( year + " is a leap year." ) ; } else { System.out.println ( year + " is not a leap year." ) ; } } else { System.out.println ( year + " is a leap year." ) ; } } else { System.out.println ( year + " is not a leap year." ) ; } }
Replies:
|