
how to create class for leap year. It is leap year if it is divisible by 4 and 400 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.