-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSwitchControlStatementDemo.java
More file actions
52 lines (51 loc) · 1.29 KB
/
SwitchControlStatementDemo.java
File metadata and controls
52 lines (51 loc) · 1.29 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
/**
* The SwitchControlStatementDemo program implements an application that
* simply demonstrates use of control statement switch in Java.
* The code displays the name of the month, based on the value of month,
* using the switch statement.
*
* @author Sarju S
* @version 1.0
* @since 2020-09-22
*/
package com.sjcet.basicPrograms;
import java.util.Scanner;
public class SwitchControlStatementDemo {
public static void main(String[] args) {
int month;
Scanner sc = new Scanner(System.in);
System.out.println("Enter an integer number between 1-12:");
month = sc.nextInt();
String monthName;
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 = "Invalid month";
break;
}
System.out.println(monthName);
sc.close();
}
}