Skip to content

Commit 60c4a30

Browse files
Check Leap Year
Check Leap Year Co-Authored-By: Manish Upadhyay <ermanishupadhyay@gmail.com>
1 parent 1f90ac1 commit 60c4a30

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/JavaPrograms/CheckLeapYear.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package JavaPrograms;
2+
3+
import java.util.Scanner;
4+
5+
public class CheckLeapYear {
6+
7+
public static void main(String[] args) {
8+
// divisible by 4 for all the century years ---> century years means years which ending with 00
9+
// century year is leap year only when its perfectly divisible by 400.
10+
//1900 is not a leap year
11+
// 2012 is a leap year
12+
13+
Scanner s = new Scanner(System.in);
14+
System.out.println("Enter a year:");
15+
int year = s.nextInt();
16+
boolean leap = false;
17+
if(year % 4 == 0) {
18+
if(year % 100 == 0) {
19+
if(year % 400 == 0) {
20+
leap = true;
21+
}
22+
else {
23+
leap = false;
24+
}
25+
}
26+
else {
27+
leap = true;
28+
}
29+
}
30+
else {
31+
leap = false;
32+
}
33+
if(leap) {
34+
System.out.println(year + " is a leap year");
35+
}
36+
else {
37+
System.out.println(year + " is not a leap year");
38+
}
39+
}
40+
41+
}

0 commit comments

Comments
 (0)