A leap year has 366 days, as opposed to a common year, which has 365. Nearly every 4 years is a Leap Year, and we add a Leap Day, an extra – or intercalary – day on February 29.
Leap Years are needed to keep our modern day Gregorian Calendar in alignment with the Earth’s revolutions around the sun. It takes the Earth approximately 365.242199 days – or 365 days, 5 hours, 48 minutes, and 46 seconds – to circle once around the Sun. This is called a tropical year.
However, the Gregorian calendar has only 365 days in a year, so if we didn’t add a day on February 29 nearly every 4 years, we would lose almost six hours off our calendar every year. After only 100 years, our calendar would be off by approximately 24 days!
In the Gregorian calendar 3 criteria must be taken into account to identify leap years:
- The year is evenly divisible by 4;
- If the year can be evenly divided by 100, it is NOT a leap year, unless;
- The year is also evenly divisible by 400. Then it is a leap year.
public class Leap
public static void main(String args)throws IOException
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a year: ");
y = Integer.parseInt(br.readLine());
if(y%4==0 && y%100!=0 || y%400==0)
System.out.println("The year is a leap year");
System.out.println("The year is not a leap year");