-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLeapYear.java
40 lines (27 loc) · 879 Bytes
/
LeapYear.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
// Sonny Li
// CMP 167: Programming Methods I
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter month: ");
int m = in.nextInt();
System.out.print("Enter day: ");
int d = in.nextInt();
System.out.print("Enter year: ");
int y = in.nextInt();
System.out.println();
if (m < 1 || m > 12 || d < 1 || d > 31 || y < 1000 || y > 9999)
{
System.out.println("\nInvalid entry.");
}
else if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
{
System.out.println(m +"/"+ d + "/" + y + " falls on a leap year.");
}
else
{
System.out.println(m + "/" + d +"/" + y + " doesn't fall on a leap year.");
}
}
}