- public class SwitchDemo
- {
- public static void main(String[] args)
- {
-
- int a=4,b =2;
- char ch = '+';
- switch(ch)
- {
- case '-':
- System.out.println(a-b);
- break;
- case '+':
- System.out.println(a+b);
- break;
- case '*':
- System.out.println(a*b);
- break;
- case '/':
- System.out.println(a/b);
- break;
- default:
- System.out.println("feifa");
- }
- }
- }
- /*
- 可以运行呀,结果为:
-
- C:\Users\hacket\Desktop>java SwitchDemo
- 6
- */
复制代码 |