- 1:case a>5不行
- 2:应该加上break,如果没有加上,最终会执行default
case后面不能是布尔类型的
Incompatible types. Found: 'boolean', required: 'int'2:应该加上break,如果没有加上,最终会执行default
package Practice;
//case a>5是不行的
public class SwitchPractice {
public static void main(String[] args) {
int a=1;
switch(a){
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
break;
default:
System.out.println(a+1);
}
System.out.println(a);
}
}
加上的结果
one 1 Process finished with exit code 0
不加的结果
one 1 2 Process finished with exit code 0



