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 LeapYear { 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 * 024 * @example 025 * <pre name="test"> 026 * isLeapYear(1900) === false 027 * isLeapYear(2000) === true 028 * isLeapYear(2003) === false 029 * isLeapYear(2004) === true 030 * isLeapYear(2010) === false 031 * </pre> 032 */ 033 public static final boolean isLeapYear(int year) { 034 if ( year % 400 == 0 ) return true; 035 if ( year % 100 == 0 ) return false; 036 if ( year % 4 == 0 ) return true; 037 return false; 038 } 039 040 /** 041 * @param args not used 042 */ 043 public static void main(String[] args) { 044 int year = 2004; 045 if ( isLeapYear(year ) ) System.out.println(year + " is a leap year"); 046 else System.out.println(year + " is not a leap year"); 047 } 048 049 }