java program to find if given year is leap year

Solutions on MaxInterview for java program to find if given year is leap year by the best coders in the world

showing results for - "java program to find if given year is leap year"
Athena
17 Aug 2020
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}