-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonthSwitch.java
More file actions
35 lines (28 loc) · 991 Bytes
/
Copy pathMonthSwitch.java
File metadata and controls
35 lines (28 loc) · 991 Bytes
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
import java.util.Scanner;
public class MonthSwitch {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to month mapping\n");
System.out.println("please enter your month number:");
int monthNum = input.nextInt();
String monthName = getMonthName(monthNum);
System.out.println("Your month name is:" + monthName);
}
public static String getMonthName(int monthNum) {
return switch (monthNum) {
case 1 -> "January";
case 2 -> "February";
case 3 -> "March";
case 4 -> "April";
case 5 -> "May";
case 6 -> "June";
case 7 -> "July";
case 8 -> "August";
case 9 -> "September";
case 10 -> "October";
case 11 -> "November";
case 12 -> "December";
default -> "invalid month";
};
}
}