Determine Leap Year Program using Java

As we know  leap year is a year that adds a day in order to adjust the calendar to the astronomical year. In a year does not exactly consist of 365 days, but 365 days 5 hours 48 minutes 45.1814 seconds. If this is ignored, then every 4 years will be short of almost 1 day (exactly 23 hours 15 minutes 0.7256 seconds). So to compensate for this, every 4 years (4 divided years), given an extra day: February 29th. But since 5 hours 48 minutes 45.1814 seconds is less than 6 hours, then the years that can be divided 100 (as in 1900), not leap years, except can be divided by 400 (as in 2000). you can find more information regarding leap year in here.

So, we shared a program to determine whether user input is leap year or not.

import java.util.Scanner;
public class Kabisat{
    public static void main(String args[]) {
  int year;
  Boolean cek = new Boolean(false);
  System.out.println(" Input year :");
  Scanner in = new Scanner(System.in);
  year = in.nextInt();
  if(year > 2005 || year < 1900)
                     System.out.println(" Limited years by 1900 to 2005.");
  else{
   if(year % 400 == 0){ cek = true;}
   else if(year % 100 == 0){}
   else if(year % 4 == 0){ cek = true;}
   else{}
   if(cek)
    System.out.println(" True.");
   else
    System.out.println(" False.");
  }
 }
}


The result of listing program above will be like this :

Remember you can edit the restriction range here as you wish 

if(year > 2005 || year < 1900)


Comments

Popular posts from this blog

Quantization of Image Data Implementation in C#

Computer Graphics Project "Planet Orbit" Source Code with Glut OpenGL

Computer Graphics Project "MINION" Source Code with Glut OpenGL