001package de.hdm_stuttgart.sd1.leap;
002
003/**
004 * Leap year calculations
005 *
006 */
007public class LeapYear {
008
009  /**
010   * @param args unused
011   */
012  public static void main(String[] args) {
013    System.out.println("Is 1800 a leap year? " + isLeapYear(1800));
014    System.out.println("Is 2000 a leap year? " + isLeapYear(2000));
015    System.out.println("Is 2016 a leap year? " + isLeapYear(2016));
016  }
017
018  /**
019   * Characterizing a given year either as leap year or
020   * non- leap year.
021   *
022   * Syntactically different implementation with regard to {@link LeapYearCompact} having
023   * exactly identical logic.
024   * 
025   * @param year The year in question.
026   * @return true if year is a leap year, false otherwise.
027   */
028  public static boolean isLeapYear(int year) {
029     if (year % 400 == 0) {         // Every 400 years we do have a leap year.
030       return true;
031     } else if (0 == year % 100) {  // No leap year if multiple of 100
032       return false;
033     } else {
034       return 0 == year % 4;        // Every 4 years we do have a leap year
035     }
036  }  
037}