-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.java
More file actions
43 lines (40 loc) · 1.24 KB
/
Switch.java
File metadata and controls
43 lines (40 loc) · 1.24 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
public class Switch {
public static void main(String[] args) {
int key = 4;
switch (key) {
case 1:
System.out.println("Case 1 is unlocked.");
break;
case 2:
System.out.println("Case 2 is unlocked.");
break;
case 3:
System.out.println("Case 3 is unlocked.");
break;
case 4:
System.out.println("Case 4 is unlocked.");
break;
case 5:
System.out.println("Case 5 is unlocked.");
break;
case 6:
System.out.println("Case 6 is unlocked.");
break;
default:
break;
}
// Output = Case 4 is unlocked.
// Now default value is executed
int day = 7;
switch (day) {
case 1 :
System.out.println("Saturday");
break;
case 2 :
System.out.println("Sunday");
break;
default :
System.out.println("Default block is executed looking forward weekend day.");
}
}
}