Check Leap Year in Java.
Check Leap Year in Java.
Here we will write a java program to check whether the input year is a leap year or not.A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.
EXAMPLE :-
import java.util.Scanner;
public class leep {
public static void main(String[] args) {
int year;
Scanner scan = new Scanner(System.in);
System.out.println("Enter any Year ::");
year = scan.nextInt();
scan.close();
boolean isLeap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
isLeap = true;
else
isLeap = false;
}
else
isLeap = true;
}
else {
isLeap = false;
}
if(isLeap==true)
System.out.println(year + " It is a Leap Year.");
else
System.out.println(year + " It is not a Leap Year.");
}
}
OUTPUT
Enter any Year ::
1996
1996 It is a Leap Year.
No comments:
Post a Comment
Please do not any spam link in Comment Box