-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNested_switch.java
More file actions
50 lines (47 loc) · 1.81 KB
/
Nested_switch.java
File metadata and controls
50 lines (47 loc) · 1.81 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
import java.util.Scanner;
public class Nested_switch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Employee ID: ");
int empId = sc.nextInt();
System.out.println("Enter the Department: ");
String dept = sc.next();
// switch(empId){
// case 0:
// System.out.println("Pratham V Bhat");
// break;
// case 1:
// System.out.println("Omkar Bhat");
// break;
// case 2:
// System.out.println("Employee Number 2");
// switch(dept) {
// case "IT":
// System.out.println("IT Departmant");
// break;
// case "MG":
// System.out.println("Management Department");
// break;
// default:
// System.out.println("Enter a valid Department");
// }
// break;
// default:
// System.out.println("Enter a valid Employee ID");
// }
// Better way to write the above code
switch(empId){
case 0 -> System.out.println("Pratham V Bhat");
case 1 -> System.out.println("Omkar Bhat");
case 2 -> {
System.out.println("Employee Number 2");
switch(dept) {
case "IT" -> System.out.println("IT Department");
case "MG" -> System.out.println("Management Department");
default -> System.out.println("Enter a valid Department");
}
}
default -> System.out.println("Enter a valid Employee ID");
}
}
}