Friday, December 23, 2011

Program to check if a year is leap year or not


import java.util.*;
public class Ch2Q4
{    public static void main(String[] args)
    {Scanner kbd = new Scanner(System.in);
     int yr;
     System.out.print("enter year: ");
     yr = kbd.nextInt();
     if(yr < 1582)
      if(yr%4==0)
       System.out.println("Leap year");
      else System.out.println("not a Leap year");
     else if(yr%400 == 0||yr%4 == 0 && yr % 100 != 0)
         System.out.println("Leap year");
       else System.out.println("Not aLeap year");
     }
}

No comments:

Post a Comment