Skip to content

Commit cba3c35

Browse files
authored
commit (#811)
1 parent 4a839ab commit cba3c35

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.comparison;
2+
3+
public class SwitchExample {
4+
public static void main(String[] args) {
5+
int number = 3;
6+
String description;
7+
switch (number) {
8+
case 0:
9+
description = "Zero";
10+
break;
11+
case 1:
12+
case 2:
13+
description = "One or Two";
14+
break;
15+
case 3:
16+
case 4:
17+
case 5:
18+
description = "Between Three and Five";
19+
break;
20+
default:
21+
description = "Other";
22+
}
23+
System.out.println(description);
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.comparison
2+
3+
fun main(number: Int): String {
4+
return when (number) {
5+
0 -> "Zero"
6+
1, 2 -> "One or Two"
7+
in 3..5 -> "Between Three and Five"
8+
else -> "Other"
9+
}
10+
}

0 commit comments

Comments
 (0)