- public class Demo3
- {
- public static void main(String[] args)
- {
- long x=2,y=1; ----------------------------》定义long型变量 :报错!
- switch((int)(x+y)) // switch 只接受byte short char int ,不支持long,但是楼主还可以用强转 就不会报错</span>
- {
- case 1:
- System.out.println(x+y);
- break;
- case 3:
- System.out.println(x+y);
- case 0:
- System.out.println(x+y);
- break;
- default:
- System.out.println("没有"+(x+y));
- break;
- }
- }
- }
复制代码
|