-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThirtyDays.java
59 lines (53 loc) · 1.3 KB
/
ThirtyDays.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
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class ThirtyDays {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int month, days;
String monthName;
System.out.print( "Which month? (1-12) " );
month = keyboard.nextInt();
switch(month) {
case 1: monthName = "January";
break;
case 2: monthName = "February";
break;
case 3: monthName = "March";
break;
case 4: monthName = "April";
break;
case 5: monthName = "May";
break;
case 6: monthName = "June";
break;
case 7: monthName = "July";
break;
case 8: monthName = "August";
break;
case 9: monthName = "September";
break;
case 10: monthName = "October";
break;
case 11: monthName = "November";
break;
case 12: monthName = "December";
break;
default: monthName = "error";
}
/* Thirty Days hath September
April, June, and November
All the rest have thrity-one
Except the second month alone...
*/
switch(month) {
case 9:
case 4:
case 6:
case 11: days = 30;
break;
case 2: days = 28;
break;
default: days = 31;
}
System.out.println( days + " days hath " + monthName );
}
}