Leap year logic with if and else statement
import java.util.*;/**
* leapyear
*/
public class leapyear {
public static void main(String[] args) {
int y;
Scanner s= new Scanner (System.in);
System.out.println("Enter the year");
y=s.nextInt();
if(y%4==0){
if(y%100==0){
if(y%400==0){
System.out.println("leap year");
}
else{
System.out.println("not a leap year");
}
}
else{
System.out.println("leap year");
}
}
else{
System.out.println("Not a leap year");
}
}
}
Comments
Post a Comment