001 package example; 002 003 /** 004 * A very simple example how to use ComTest as a 005 * definition and testing tool. 006 * 007 * In this first example we test simple function. 008 * 009 * @author vesal 010 * @version 8.6.2010 011 */ 012 public class LeapYearReady { 013 014 /** 015 * Check if year is a leap year. 016 * 017 * Year is a leap year if it is divisible by 4. 018 * Unless it is divisible by 100. But years divisible by 400 are leap years. 019 * (maybe year 4000 will not be?) 020 * 021 * @param year to check 022 * @return true if is a leap year, otherwise false 023 * @example 024 * <pre name="test"> 025 * isLeapYear(1900) === false; // divisible by 100 026 * isLeapYear(2000) === true; // divisible by 400 027 * isLeapYear(2003) === false; // odd number 028 * isLeapYear(2004) === true; // divisible by 4 029 * isLeapYear(2010) === false; // not divisible by 4 030 * </pre> 031 */ 032 public static final boolean isLeapYear(int year) { 033 if ( year % 400 == 0 ) return true; 034 if ( year % 100 == 0 ) return false; 035 return year %4 == 0; 036 } 037 038 /** 039 * @param args not used 040 */ 041 public static void main(String[] args) { 042 int year = 2004; 043 if ( isLeapYear(year ) ) System.out.println(year + " is a leap year"); 044 else System.out.println(year + " is not a leap year"); 045 } 046 047 }