- package com;
- /**
- * 根据操作符做相应的操作
- *
- * @author Denny
- *
- */
- public class SwitchTest2 {
- public static void main(String[] args) {
- int a = 10;
- int b = 3;
- char c = '+';
- switch (c) {
- default:
- System.out.println("未知操作符");
- case '+':
- System.out.println("a+b=" + (a + b));
- case '-':
- System.out.println("a-b=" + (a - b));
- case '*':
- System.out.println("a*b=" + (a * b));
- case '/':
- System.out.println("a/b=" + (a / b));
- }
- }
- }
复制代码
|
|