在 Java 中,是否可以编写一个 switch 语句,其中每个 case 包含多个值?例如(虽然下面的代码显然不能工作) :
switch (num) {
case 1 .. 5:
System.out.println("testing case 1 to 5");
break;
case 6 .. 10:
System.out.println("testing case 6 to 10");
break;
}
我认为这可以在 Objective C 中完成,在 Java 中有类似的东西吗?或者我应该只使用 if
,else if
语句代替?