How to check if given year is a leap year or not in Java - The Coding Shala

Home >> Java Program >> check leap year

 In this post, we will learn how to check if a given year is a leap year or not. We will write a Java Program to check leap year.

Java Program to check leap year

Leap years are those years in which the year's number is either divisible by 4 but not divisible by 100 or divisible by 400.

Example 1:
Input: 2100
Output: Regular

Example 2:
Input: 2000
Output: Leap

Java Program: 

import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        // put your code here
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            System.out.println("Leap");
        } else {
            System.out.println("Regular");
        }
    }
}


Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

N-th Tribonacci Number Solution - The Coding Shala

Find Second Smallest Element in the Array - The Coding Shala

New Year Chaos Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala