Go to Top

Sunday 2 October 2011

Utilities 11 : Leap year

Here's another great tool for checking whether a particular year was / is / will be a leap year or not. Just copy and compile it.

Java Program :

import java.io.*;
class leap
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     int y,s=0;
     System.out.print("Enter an year number : ");
     y=Integer.parseInt(br.readLine());
     s=y%100;
     if(s==0)
     {
        if(y%400==0)
        System.out.print("\nThe year was / is / will be a leap year");
        else
        System.out.print("\nThe year was / is / will not be a leap year");
    }
    else
    {
        if(y%4==0)
        System.out.print("\nThe year was / is / will be a leap year");  
        else
        System.out.print("\nThe year was / is / will not be a leap year");
    }
    }
}

No comments:

Post a Comment

ShareThis