leap year checker java

Solutions on MaxInterview for leap year checker java by the best coders in the world

showing results for - "leap year checker java"
Riccardo
20 Nov 2019
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}
Jan
18 May 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}
Beatrice
20 Feb 2016
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
queries leading to this page
leap year logic in java to input 2020leap year meaning in javaleapyear program in javaprogram to find leap year javacode of leap year in javajava program to check whether the given year is leap year or nothow to check whether the given year is leap or not in javagiven a year check if the year is leap year or not in javahow to check if february and leap year javaleap year javaprogram to find leap year or not in javawrite a java program to find whether the given year is leap year or not using conditionala leap year java programleap year concept in javajava test if it is leap yearwrite a java program to find whether a year entered by the user is a leap year or notleap year checker javaleap year calculator javajava leap year questionfollowing year is leap year javahow to account for leap years in java programleap year program injavaleap year or not in javajava calendar know if year is leapleap in javaleap year checking in javahow to determine a leap year javajava leap year codejava code to check leap yearjava program to check leap year 28nested if 29java leap yearsleap year logic in javajava code leap yearleap year formula javahow to calculate if a year is a leap year javaleapyear javajava program to check whether a given year is leap or not using scannerjava method to find year is leap or notleap year program in javafind out if an year is leap javaleap year in javajava lep yearleap year java best wayleap year check using calander in java symbol java statement this year is leap or notis leap javajava leap year expressionleap year condition in javahow to check if a given year is a leap year in java 3fjava program to check leap yearwrite a program to check whether a given year is a leap year or not in javajava leap year calculatorwhen does a leap year start javaleap year code in avajava check leap yearhow to check if leap year in javajava program to check leap year or notleap year program in java using methodhow to find leap year in javaleap year calculation if statement javagiven 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 javaprogram to calculate leap year in javawap to generate a year using random class and check whether it is leap or not using user defined package best way to know if leap year javacheck if year is leap year javahow to know a leap year javajava code for leap year or nothow to calculate a leap year in javaleap year calendar javahow to check for leap year in javaprogram to determine leap year in javawrite a program in java to check if its a leap yearjava code for leap yearwrite a program to find leap year in javacheck leap year using time in javajava program to leap yearleap year if statementread year and check if the given year is a leap year javahow to check year is leap year or not in javafunction year leap javacheck leap year or not in javaprogram to find leap year in javacalculating lea year javaleap year java program randommathjava method to calculate whether a leap year or notleap year program in java with explanationwrite a program to check leap year in javaleap year calculation logic javacheck if the year is a leap year or not in javacalculate leap year javaleap year function in javaleap year java programleap year check in javaleap year java codejava date get if year is leapjava check for leap yearjava exception to find leap yearbest to detect leap year javaleap year code in javafind a leap year in javahow to check if leap year javasee if is a leap year javaprint the leap year javajava if year is leapjava program to find if given year is leap yearjava leap yearleap year condition javaleap year java loopcode for leap year in javacheck leap year javadeterminnig leap year in javahow to find wheter a year is leap year or not in javaleap year calculation javajava program to check whether a given year is leap or notcheck if the year is a leap year or not in java gfgfind if the year is leap or not in javaleap year programming in javahow to calculate leap year in javahow to check whether the year is leap or not in javafind leap year or not in javais leap year javaleap year code javahow to know if a year is a leap year javajava leapyearfind if the year is leap year in javajava check if year is leap methodgive the year and check if the leap year are not in javaleap year conditions in javajava code to check whether a year is a leap year or notleap year or not javajava program to know if the year is a leap yearcheck for leap year in javaleap year logic javajava leap year programcheck if year is a leap year javaleap year java program input from keyboardhow to find if a year is a leap year in javais leap year method javajava how to calculate leap yearfind leap year from date in javaleap year write a method in javajava program to see if its leap year or notjava is leap yearhow to determine if a year is a leap year in javacheck to see if a number is a leapyear javajava leapyear 28 29 methodjava code to find leap year or notfind leap year in javahow to check leap year in javawrite a java program to find if a year is leap year or not using for loopcheck if a year is a leap year javajava get leap yearwhat is a leap year javaleap year java methodleap year if statement javajava leap year check logicjava program to find a leap year notfinding leap year in javacondition for leap year in javais leap year code javaleapyear in javaleap year calculation in javacheck leap year in java stack overflowwhether a year is leap or not javawrite a program to input year from user and check whether the give0n year is leap year or not using if else javaleap year program in java test caseswrite a java program to check the leap yearjava leap year calcultorhow to count leap year on javafind leap year javacheck leap year in javajava find if a year is leap or notjava program for leap yearjava leap year methodleap year program javacheck if year is leap javajava check if year is leaphow to find a leap year in javawrite a java program to find whether a given year is leap year or notwap to generate a year using random class and check whether it is leap or not using user defined packagejava check if leap yearleap year checker java