java check if year is leap

Solutions on MaxInterview for java check if year is leap by the best coders in the world

showing results for - "java check if year is leap"
Paula
16 Sep 2017
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}
Montserrat
10 Jul 2017
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}
Marley
11 Jan 2018
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
Christopher
15 Feb 2016
1      boolean isLeap =  new GregorianCalendar().isLeapYear(2020);
2      //returns true
3
Philippine
17 Sep 2018
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");
Joshua
04 Apr 2017
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}
queries leading to this page
condition for leap year in javajava leapyear 28 29 methodis leap year method javafind out if an year is leap javajava leap year calculatorleap year program in javaprogram to check leap year in javahow to account for leap years in java programwrite a program to check whether a given year is a leap year or not in javajava code for leap yearleap year program javahow to know if a year is a leap year javasymbol java statement this year is leap or notwrite a java program to check the leap yearcheck if year is leap year javajava leap yearswrite a java program to find if a year is leap year or not using for loopjava check leap yearleap year in java methodjava program for leap yeargive the year and check if the leap year are not in javawrite a program to input year from user and check whether the give0n year is leap year or not using if else javahow to check if february and leap year javajava lep yearprint the leap year javahow to determine a leap year javato check a leap year using random javaleap year concept in javaleap year javaleap year program in java test caseswrite a program to check leap year in javawrite a program in java to check if its a leap yearjava find if a year is leap or notalgorithm for leap year javacheck leap year or not in javaprogram to find leap year or not in javaleap year conditions in javaleap year formula javaleap year calculation if statement javajava code leap yearwrite a java program that takes a year from user and print whether that year is a leap year or not 5b4 5dprogram to calculate leap year in javahow to check if leap year in javahow to find wheter a year is leap year or not in javaleap year java program randommathhow to check if a year is a leap year javahow to count leap year on javaleap year calculation in javajava program to check leap year 28nested if 29check if the year is a leap year or not in javadeterminnig leap year in javajava code to check leap yearleap year calculation logic javajava program to check whether a given year is leap or not using scannerjava program to check whether the given year is leap year or notleap year requirements javajava program to find leap yearleap year java best wayleapyear program in javawrite a java program that takes a year from user and print whether that year is a leap year or notis leap year javaprogram to determine leap year in javajava code to find leap year or notwrite a java program to find whether the given year is leap year or not using conditionaljava leap year questionwrite a java program that finds a given year is leap year or notcalculating lea year javajava program to check leap yearhow to find if a year is a leap year in javaleap year condition javaleap year check in javabest to detect leap year javafinding leap year in javawrite a java program to find whether a year entered by the user is a leap year or notjava leap yearhow to calculate a leap year in javacheck if year is a leap year javacalculate leap year javaprogram to find leap year in javahow to check year is leap year or not in javahow to check whether the given year is leap or not in javajava program to find a leap year notleap year checker javajava how to calculate leap yearfind leap year javacheck leap year using time in javawrite a java program to find whether a given year is leap year or not with variable table how to check if leap year javaread year and check if the given year is a leap year javahow to find a leap year in javahow to calculate leap year in javajava check if year is leap methodhow to check leap year in javafind a leap year in javawrite a java program that takes a year from user and print whether that year is a leap year or not java leapyearjava program to see if its leap year or notcheck if year is leap javahow to check whether the year is leap or not in javajava is leap yearleap year java methodleapyear javaleap year if statement javajava program to leap yearjava program to check whether a given year is leap or notleap year check using calander in java given the year input value 2c determine if that year was a leap year if a number is evenly divisible by 4 2c but not evenly divisible by 100 then it is a leap year coding in javaleap year java loopwap to generate a year using random class and check whether it is leap or not using user defined packagejava code for leap year or notwhether a year is leap or not javagiven a year check if the year is leap year or not in javaleap year java program for beginnersbest way to know if leap year javacheck if the year is a leap year or not in java gfgleap year code javawhat is a leap year javajava leap year check logicjava test if it is leap yearjava check if leap yearhow to determine if a year is a leap year in javaleap year write a method in javaleap year or not in javaleapyear in javaprogram to check leap yearjava code to check whether a year is a leap year or nothow to do leap years in javajava method to find year is leap or notfind leap year or not in javahow to check if a given year is a leap year in java 3ffind leap year in javahow to know a leap year javasee if is a leap year javacheck if a year is a leap year javaif year is divisible by 4 in javacheck leap year javacheck leap year in java stack overflowleap year program injavafind if the year is leap or not in javajava check if year is leapcheck to see if a number is a leapyear javahow to calculate if a year is a leap year javajava if year is leapjava leap year calcultorleap year calculation javaleap year calculator javaleap year program in java with explanationhow to find leap year in javafollowing year is leap year javajava function to get leap yearcheck for leap year in javajava exception to find leap yearleap year code in avaleap year code in javaprogram to find leap year javaleap year function in javaleap year if statementhow to check for leap year in javaequation to find out leap year in javaleap year in javaa leap year java programleap year logic in java to input 2020java leap year methodjava program to know if the year is a leap yearleap year java codealgorithm of program to find that entered year is leap year or notleap year or not javajava get leap yearjava check for leap yearjava leap year programwrite a program to find leap year in javacheck leap year in javajava date get if year is leapjava write a program to check leap year 3f formula a year is a leap 2c if it is divisible by 4 and 400 but 2c not by 100 28if else statement 29how to check leap year javaleap year programming in javawrite a java method to check whether an year 28integer 29 entered by the user is a leap year or not is leap javafind leap year from date in javaleap year calendar javajava calendar know if year is leapwhen does a leap year start javajava method to calculate whether a leap year or notis leap year code javaleap year logic javaleap year condition in javacode for leap year in javajava program to find if given year is leap yearfind if the year is leap year in javajava program to check leap year or notleap year java programwap to generate a year using random class and check whether it is leap or not using user defined package leap in javaleap year checking in javawrite a java program to find whether a given year is leap year or notleap year java program input from keyboardfunction year leap javaleap year meaning in javacode of leap year in javajava leap year codeleap year logic in javajava leap year expressionleap year program in java using methodjava check if year is leap