How to check if given year is a leap year or not in Java - The Coding Shala
Home >> Java Program >> check leap year
Other Posts You May Like
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"); } } }
- Java Program to add two numbers
- Java Program to find the sum of digits of a number
- Two Sum Problem
- Plus One
- Pascal Triangle
Comments
Post a Comment