-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch_Case.java
More file actions
51 lines (42 loc) · 1.28 KB
/
Switch_Case.java
File metadata and controls
51 lines (42 loc) · 1.28 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
public class Switch_Case{
public static void main(String[]args){
/*The switch statement in Java is used when you want to
excecute one block of code out of multiple options based
on the value of a variable
switch (expression){
case value1:
//code if expression == value1
break;
case value2:
//code if expression ==value2
break;
case valie2:
//code if expression ==value2
break;
default:
//code if no case matches
}
EXAMPLE
*/
int day = 3;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("Invalid Day");
break;
}
/*
Use break; to stop dall-through to the next case.
default: is optional but useful.
You can use strings, enums, or int/char types in a switch
*/
}
}