-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonth_Switch.java
More file actions
32 lines (28 loc) · 1002 Bytes
/
Month_Switch.java
File metadata and controls
32 lines (28 loc) · 1002 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
import java.util.Scanner;
public class Month_Switch {
public static void main(String[] args) {
System.out.println("Welcome to Month of the year");
Scanner input =new Scanner(System.in);
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 Number";
};
}
}