Create a new class with name Chk_leapyear:
Enter the year you want to check in the output window as shown above.
(Comment if you have any doubts)
import java.util.Scanner;
public class Chk_leapyear {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter a year to check if it is leap year : ");
int year = sc.nextInt();
System.out.println("You entered : "+year);
if(year%100==0){
if(year%400==0)
System.out.println(year+" is a leap year");
else
System.out.println(year+" is not a leap year");
}
else{
if(year%4==0)
System.out.println(year+" is a leap year");
else
System.out.println(year+" is not a leap year");
}
}
}
Output:(Click on image to enlarge)public class Chk_leapyear {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter a year to check if it is leap year : ");
int year = sc.nextInt();
System.out.println("You entered : "+year);
if(year%100==0){
if(year%400==0)
System.out.println(year+" is a leap year");
else
System.out.println(year+" is not a leap year");
}
else{
if(year%4==0)
System.out.println(year+" is a leap year");
else
System.out.println(year+" is not a leap year");
}
}
}
Enter the year you want to check in the output window as shown above.
(Comment if you have any doubts)