forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSwitch.java
More file actions
43 lines (41 loc) · 887 Bytes
/
StringSwitch.java
File metadata and controls
43 lines (41 loc) · 887 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
33
34
35
36
37
38
39
40
41
42
43
package com.examplehub.basics;
public class StringSwitch {
public static void main(String[] args) {
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
/*
* output:
* 1
* 2
* 3
* 4
* 5
* 6
* 7
*/
for (String day : days) {
switch (day) {
case "Monday":
System.out.println(1);
break;
case "Tuesday":
System.out.println(2);
break;
case "Wednesday":
System.out.println(3);
break;
case "Thursday":
System.out.println(4);
break;
case "Friday":
System.out.println(5);
break;
case "Saturday":
System.out.println(6);
break;
case "Sunday":
System.out.println(7);
break;
}
}
}
}