- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to find if the given number is a leap year?
Finding a year is a leap or not is a bit tricky. We generally assume that if a year number is evenly divisible by 4 is a leap year. But it is not the only case. A year is a leap year if −
- 1. It is evenly divisible by 100
- 2. If it is divisible by 100, then it should also be divisible by 400
- 3. Except this, all other years evenly divisible by 4 are leap years.
Algorithm
- 1. Take integer variable year
- 2. Assign a value to the variable
- 3. Check if the year is divisible by 4 but not 100, DISPLAY "leap year"
- 4. Check if the year is divisible by 400, DISPLAY "leap year"
- 5. Otherwise, DISPLAY "not leap year"
Example
import java.util.Scanner; public class LeapYear { public static void main(String[] args){ int year; System.out.println("Enter an Year :: "); Scanner sc = new Scanner(System.in); year = sc.nextInt(); if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) System.out.println("Specified year is a leap year"); else System.out.println("Specified year is not a leap year"); } }
Output 1
Enter an Year :: 2020 Specified year is a leap year
Output 2
Java Programming questions 31 Enter an Year :: 2017 Specified year is not a leap year
- Related Articles
- JavaScript program to check if a given year is leap year
- Program to check if a given year is leap year in C
- Golang Program to Check Whether a Given Year is a Leap Year
- How to detect if a given year is a Leap year in Oracle?
- Check if a given year is leap year in PL/SQL
- PHP program to check if a year is leap year or not
- Java Program to Check Leap Year
- C++ Program to Check Leap Year
- Java program to find if the given number is positive or negative
- How to find a leap year using C language?
- Checking for a Leap Year using GregorianCalendar in Java
- Java Program for check if a given number is Fibonacci number?
- Python Pandas - Check whether the year is a leap year from the Period object
- How can we calculate the number of seconds in a leap year?
- How to find leap year or not in android using year API class?

Advertisements