1import java.util.Scanner;
2public class LeapYear {
3 public static void main(String[] args){
4 int year;
5 System.out.println("Enter an Year :: ");
6 Scanner sc = new Scanner(System.in);
7 year = sc.nextInt();
8
9 if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
10 System.out.println("Specified year is a leap year");
11 else
12 System.out.println("Specified year is not a leap year");
13 }
14}
1public class LeapYear {
2
3 public static void main(String[] args) {
4
5 int year = 1900;
6 boolean leap = false;
7
8 if(year % 4 == 0)
9 {
10 if( year % 100 == 0)
11 {
12 // year is divisible by 400, hence the year is a leap year
13 if ( year % 400 == 0)
14 leap = true;
15 else
16 leap = false;
17 }
18 else
19 leap = true;
20 }
21 else
22 leap = false;
23
24 if(leap)
25 System.out.println(year + " is a leap year.");
26 else
27 System.out.println(year + " is not a leap year.");
28 }
29}
1public class LeapYear {
2
3 // Method to check leap year
4 public static void checkLeapYear(int year) {
5 if (year % 400 == 0) {
6 System.out.println(year + " is a leap year.");
7 } else if (year % 100 == 0) {
8 System.out.println(year + " is not a leap year.");
9 } else if (year % 4 == 0) {
10 System.out.println(year + " is a leap year.");
11 } else {
12 System.out.println(year + " is not a leap year.");
13 }
14
15 }
16
17 public static void main(String[] args) {
18 // Examples
19 checkLeapYear(1998);
20 checkLeapYear(2000);
21 }
22}
23
24Output:
25
261998 is not a leap year.
272000 is a leap year.