-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathprogram.java
More file actions
66 lines (52 loc) · 1.24 KB
/
program.java
File metadata and controls
66 lines (52 loc) · 1.24 KB
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
64
65
66
// Java program to find a leap year
// Importing Classes/Files
import java.io.*;
// Class for leap-year dealing
public class GeeksforGeeks {
// Method to check leap year
public static void isLeapYear(int year)
{
// flag to take a non-leap year by default
boolean is_leap_year = false;
// If year is divisible by 4
if (year % 4 == 0) {
// To identify whether it
// is a century year or
// not
if (year % 100 == 0) {
// Checking if year is divisible by 400
// therefore century leap year
if (year % 400 == 0) {
is_leap_year = true;
}
else {
is_leap_year = false;
}
}
// Out of if loop that is Non century year
// but divisible by 4, therefore leap year
is_leap_year = true;
}
// We land here when corresponding if fails
// If year is not divisible by 4
else
// Flag dealing- Non leap-year
is_leap_year = false;
if (!is_leap_year) {
System.out.println(year + " : Non Leap-year");
}
else {
System.out.println(year + " : Leap-year");
}
}
// Main Driver Code
public static void main(String[] args)
{
// Calling our function by
// passing century year
isLeapYear(2000);
// Calling our function by
// passing Non-century year
isLeapYear(2002);
}
}