-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathLeapYear.java
63 lines (54 loc) · 1.14 KB
/
LeapYear.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.java.basic;
import java.util.Scanner;
/*
* LEAP YEAR
* ---------
* This program is to check the given number is leap year or not.
*
* Leap Year Conditions
* 1. Year should be divisible by 4
* 2. If it is divisible by 100 then should be divisible by 400
* 3. If both conditions are not satisfied, then given input is not leap year.
*
* Example
* 2000 - LEAP YEAR
* 2100 - NOT A LEAP YEAR
* 2020 - LEAP YEAR
* 2019 - NOT A LEAP YEAR
* 1900 - NOT A LEAP YEAR
* 1996 - LEAP YEAR
*/
public class LeapYear {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a year :: ");
int year = scanner.nextInt();
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
System.out.println("YES LEAP YEAR!");
else
System.out.println("No its not leap year.");
scanner.close();
}
}
/*
INPUT
Enter a year :: 2020
OUTPUT
YES LEAP YEAR!
INPUT
Enter a year :: 2000
OUTPUT
YES LEAP YEAR!
INPUT
Enter a year :: 1996
OUTPUT
YES LEAP YEAR!
INPUT
Enter a year :: 2100
OUTPUT
No its not leap year.
INPUT
Enter a year :: 2019
OUTPUT
No its not leap year.
*/