在每个案例中使用具有一定范围值的switch语句?

20 浏览
0 Comments

在每个案例中使用具有一定范围值的switch语句?

在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中有类似的东西吗?或者我应该使用ifelse if语句来代替?

0