-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_NumberDaysInMonth.java
More file actions
65 lines (45 loc) · 1.25 KB
/
13_NumberDaysInMonth.java
File metadata and controls
65 lines (45 loc) · 1.25 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
public class NumberOfDaysInMonth {
public static boolean isLeapYear(int year){
if(year < 1 || year > 9999)
return false;
if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return true;
else
return false;
}
public static int getDaysInMonth(int month, int year){
if(month < 1 || month > 12 || year < 1 || year > 9999)
return -1;
switch(month){
case 1:
return 31;
case 2:
if(isLeapYear(year) == true)
return 29;
else
return 28;
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
default:
return -1;
}
}
}