Friday, October 18, 2013

Java Program to test whether a given year is a leap year or not


Code:-

import java.util.Scanner;
class Leap{
public static void main(String args[]){
System.out.println("Enter year");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if((a%100)==0){
if((a%400)==0)
System.out.println(a+" is a century year and a leap year too");
else
System.out.println(a+" is a century year");
}
else{
if((a%4)==0)
System.out.println(a+" is leap year ");
else
System.out.println(a+" is not a leap year");
}
}
}

Output:-


No comments:

Post a Comment

Ads Inside Post