Monday, 14 March 2016

Findout the leap year in java

To find out a given year to be leap year or not.The coding in java.

import java.io.*;
class leapyear
{
public static void main(String args[])throws IOException
{
int a;
DataInputStream l = new DataInputStream(System.in);
a=Integer.parseInt(l.readLine());
if(a%4==0)
{
  if(a%100==0)
   {
    
    if(a%400==0)
     {
       System.out.println("Leap Year");
     }
     else
     {
       System.out.println("Nota Leap Year");
      }
    }
  else
   {
    System.out.println("Leap Year");
    }
 }
else
{
 System.out.println("Not a Leap Year");
}
}
}


Set the path and compile the file.

C:\Documents and Settings\dcom358>H:

H:\>path=C:\jdk1.3\bin;

H:\>javac leapyear.java
Note: leapyear.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

H:\>java leapyear
2015
Not a Leap Year

H:\>java leapyear
2012
Leap Year