-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleap.java
More file actions
24 lines (19 loc) · 795 Bytes
/
leap.java
File metadata and controls
24 lines (19 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class leap {
public static void main (String[] args) {
// a year is a leap year if it is divisible by 4
// if the year is divisible by 100, then it is a leap year when it is only divisible by 400
Scanner scanner = new Scanner (System.in);
System.out.println("Give a year:");
int year = Integer.valueOf(scanner.nextLine());
if (year % 100 == 0 && year % 400 == 0) {
System.out.println("The year "+ year + (" is a leap year"));
}
else if (year % 4 == 0) {
System.out.println("The year "+ year + (" is a leap year"));
}
else {
System.out.println("The year "+ year + (" is not a leap year"));
}
}
}