
write a java program that takes an input as a keyboard inputs or command line argument, a year between 1800 and 2000 and then reports whether itis a leap year. Aleap year is an integer greater than 1584 that is either divisible by 400 or is divisible by 4 but not 100

Hi Friend,
Try the following code:
import java.util.*;
public class LeapYear{
public static boolean isLeapYear(int year) {
if (year < 0) {
return false;
}
if (year % 4 == 0) {
return true;
} else if (year % 400 == 0) {
return true;
}
else if (year % 100 == 0) {
return false;
}
else {
return false;
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter any year:" );
int y = in.nextInt();
LeapYear year = new LeapYear();
if (year.isLeapYear(y)){
System.out.println("It is a leap year.");
}
else{
System.out.println("It is not a leap year.");
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.