- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtutorial_23.java
More file actions
Latest commit
53 lines (47 loc) · 2.04 KB
/
Copy pathtutorial_23.java
File metadata and controls
53 lines (47 loc) · 2.04 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
importjava.util.Scanner;
classDriver {
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
System.out.print("Enter a month : ");
if (scan.hasNextInt()) {
intintMonth = scan.nextInt();
switch (intMonth) {
case1: case2: case12:
System.out.printf("Month %d is in winter.\n", intMonth);
break;
case3: case4: case5:
System.out.printf("Month %d is in spring.\n", intMonth);
break;
case6: case7: case8:
System.out.printf("Month %d is in fall.\n", intMonth);
break;
case9: case10: case11:
System.out.printf("Month %d is in summer.\n", intMonth);
break;
default:
System.out.println("Invalid month!");
break; // optional
}
}
else {
StringstrMonth = scan.next().toLowerCase();
switch (strMonth) {
case"jan": case"january": case"feb": case"feburary": case"dec": case"december":
System.out.printf("%s is in winter.\n", strMonth);
break;
case"mar": case"march": case"apr": case"april": case"may":
System.out.printf("%s is in spring.\n", strMonth);
break;
case"jun": case"june": case"jul": case"july": case"aug": case"august":
System.out.printf("%s is in fall.\n", strMonth);
break;
case"sep": case"september": case"oct": case"october": case"nov": case"november":
System.out.printf("%s is in summer.\n", strMonth);
break;
default:
System.out.println("Invalid month!");
break; // optional
}
} //end if
}
}