-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeapYearCalculatorJava.java
48 lines (35 loc) · 1.06 KB
/
LeapYearCalculatorJava.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
/**
* @author Adam Schilperoort
* Homework 2, CS 136
*/
import java.util.Scanner;
public class LeapYearCalculatorJava {
public static void main(String[] args) {
System.out.print("Enter the year you want to check: ");
Scanner sc = new Scanner(System.in);
int Year = sc.nextInt();
boolean LeapYear= false;
//int year = (new Scanner(System.in)).nextInt();
if (Year <= 1582){
System.out.println("The Gregorian correction doesn't apply. Cannot compute.");
System.exit(0);
}
if (Year%400 == 0){ //simple logic tiers to determine which years are leap years
LeapYear= true;
}
else if (Year%100 ==0){
LeapYear= false;
}
else if (Year%4 ==0){
LeapYear= true;
}
if(LeapYear ==true){
System.out.print(+Year);
System.out.println(" is a leap year!");
}
else{
System.out.print(+Year);
System.out.println(" isn't a leap year.");
}
}
}