Java Leap Year Check isLeapYear(int year)

Here you can find the source of isLeapYear(int year)

Description

return the leap year for years 1581-8999.

License

Open Source License

Parameter

Parameter Description
year the four-digit year.

Return

true if the year is a leap year.

Declaration

public static boolean isLeapYear(int year) 

Method Source Code

//package com.java2s;
/*/*from   w w  w  .  jav  a2  s  . c om*/
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

public class Main {
    /**
     * return the leap year for years 1581-8999.
     * @param year the four-digit year.
     * @return true if the year is a leap year.
     */
    public static boolean isLeapYear(int year) {
        if (year < 1000)
            throw new IllegalArgumentException("year must be four-digits");
        return (year % 4) == 0 && (year % 100 != 0 || year % 400 == 0);
    }
}

Related

  1. isLeapYear(int year)
  2. isLeapYear(int year)
  3. isLeapYear(int year)
  4. isLeapYear(int year)
  5. isLeapYear(int year)
  6. isLeapYear(int year)
  7. isLeapYear(int year)
  8. isLeapYear(Integer year)
  9. isLeapYear(long year)