File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments