package example; /** * A very simple example how to use ComTest as a * definition and testing tool. * * In this first example we test simple function. * * @author vesal * @version 8.6.2010 */ public class LeapYearReady { /** * Check if year is a leap year. * * Year is a leap year if it is divisible by 4. * Unless it is divisible by 100. But years divisible by 400 are leap years. * (maybe year 4000 will not be?) * * @param year to check * @return true if is a leap year, otherwise false * @example *
* isLeapYear(1900) === false; // divisible by 100 * isLeapYear(2000) === true; // divisible by 400 * isLeapYear(2003) === false; // odd number * isLeapYear(2004) === true; // divisible by 4 * isLeapYear(2010) === false; // not divisible by 4 **/ public static final boolean isLeapYear(int year) { if ( year % 400 == 0 ) return true; if ( year % 100 == 0 ) return false; return year %4 == 0; } /** * @param args not used */ public static void main(String[] args) { int year = 2004; if ( isLeapYear(year ) ) System.out.println(year + " is a leap year"); else System.out.println(year + " is not a leap year"); } }