Java Program to check Leap Year

In this post, we will learn how to check whether the year is a leap year or not.


Implementation Using Java:

import java.util.Scanner;
public class CheckLeapYear {
		public static void main(String[] args) {
	    	Scanner sc=new Scanner(System.in);
	    	System.out.println("Enter year");
	        int year = sc.nextInt();
	        boolean leap = false;
                if(year % 4 == 0)
	        {
	            if( year % 100 == 0)
	            {
	                if ( year % 400 == 0)
	                    leap = true;
	                else
	                    leap = false;
	            }
	            else
	                leap = true;
	        }
	        else
	            leap = false;

	        if(leap)
	            System.out.println(year + " is a leap year.");
	        else
	            System.out.println(year + " is not a leap year.");
	    }
	}

Output:
Enter year 1999
1999 is not a leap year.

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor

Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #interview #placement #learn #computer #science

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door