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}
1import java.time.LocalDate;
2import java.time.LocalDateTime;
3import java.time.Year;
4import java.time.ZonedDateTime;
5
6public class Main
7{
8 public static void main(String[] args)
9 {
10 // 1. ZonedDateTime
11
12 ZonedDateTime currentTime = ZonedDateTime.now();
13
14 if (currentTime.toLocalDate().isLeapYear())
15 {
16 System.out.println(currentTime.getYear() + " is a leap year");
17 } else {
18 System.out.println(currentTime.getYear() + " is NOT a leap year");
19 }
20
21 // 2. LocalDateTime
22
23 LocalDateTime localDateTime = LocalDateTime.now();
24
25 if (localDateTime.toLocalDate().isLeapYear())
26 {
27 System.out.println(localDateTime.getYear() + " is a leap year");
28 } else {
29 System.out.println(localDateTime.getYear() + " is NOT a leap year");
30 }
31
32 // 3. LocalDate
33
34 LocalDate localDate = LocalDate.now();
35
36 if (localDate.isLeapYear())
37 {
38 System.out.println(localDate.getYear() + " is a leap year");
39 } else {
40 System.out.println(localDate.getYear() + " is NOT a leap year");
41 }
42
43 //4. Check current year is leap year or not
44
45 if (Year.now().isLeap())
46 {
47 System.out.println("Current year is a leap year");
48 } else {
49 System.out.println("Current year is NOT a leap year");
50 }
51 }
52}
53
1 boolean isLeap = new GregorianCalendar().isLeapYear(2020);
2 //returns true
3
1import java.util.Scanner;
2public class leapyear {
3 public static void main(String[] args)
4 {
5 Scanner myScanner = new Scanner(System.in);
6 System.out.println("Enter in the year ");
7 int year=myScanner.nextInt();
8
9 if(year%4==0)
10 if(year%100==0)
11 if(year%400==0)
12 System.out.println("It is a leap year");
13 else
14 System.out.println("it is not a leap year");
15 else System.out.println("It is a leap year");
16 else
17 System.out.println("Is not a leap year");
1import java.util.Scanner;
2public class LeapYearDemo
3{
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 System.out.println("Please enter any year: ");
8 int year = sc.nextInt();
9 boolean temp = false;
10 if(year % 400 == 0)
11 {
12 temp = true;
13 }
14 else if(year % 100 == 0)
15 {
16 temp = false;
17 }
18 else if(year % 4 == 0)
19 {
20 temp = true;
21 }
22 else
23 {
24 temp = false;
25 }
26 if(temp)
27 {
28 System.out.println("Year " + year + " is a Leap Year");
29 }
30 else
31 {
32 System.out.println("Year " + year + " is not a Leap Year");
33 }
34 sc.close();
35 }
36}