Check leap year

Check leap year

Easy Java Control Flow 18 views
Explanation Complexity

Problem Statement

Task: return true if year is leap year using correct rules (divisible by 400, or divisible by 4 but not 100).

Input Format

An integer year.

Output Format

true if leap year, otherwise false.

Example

2000
true

Constraints

• year ≥ 1

• Use correct leap year rules

Concept Explanation

A year is a leap year if:

• It is divisible by 400, OR

• It is divisible by 4 but not divisible by 100.

Step-by-Step Explanation

1.Read integer year.

2.If year % 400 == 0, return true.

3.Else if year % 4 == 0 and year % 100 != 0, return true.

4.Else return false.

Concept Explanation

A year is a leap year if:

• It is divisible by 400, OR

• It is divisible by 4 but not divisible by 100.

Step-by-Step Explanation

1.Read integer year.

2.If year % 400 == 0, return true.

3.Else if year % 4 == 0 and year % 100 != 0, return true.

4.Else return false.

Input / Output Format

Input Format
An integer year.
Output Format
true if leap year, otherwise false.
Constraints
• year ≥ 1

• Use correct leap year rules

Examples

Input:
2000
Output:
true

Example Solution (Public)

Java
static boolean isLeap(int y){return (y%400==0)||((y%4==0)&&(y%100!=0));}

Official Solution Code

static boolean isLeap(int y){return (y%400==0)||((y%4==0)&&(y%100!=0));}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.