/** * 需求:基本练习,输入/*-+运算; * 思路:switch * { * case: * break; * } 语句; * * 步骤:略 */ import java.util.Scanner; public class Demo_1{ public static void main(String[] arge) { Scanner input = new Scanner(System.in); System.out.println("please enter a /or*or-or+: "); char option=input.next().charAt(0);//输入/*-+ Scanner input1 = new Scanner(System.in); System.out.println("please enter tow number a and b "); int a = input1.nextInt(); int b= input1.nextInt(); switch (option) { case '+': System.out.println("a+b="+(a+b)); break; case '-': System.out.println("a-b="+(a-b)); break; case '*': System.out.println("a*b="+(a*b)); break; case '/': System.out.println("a/b="+(a/b)); break; case '%': System.out.println("a%b="+(a%b)); break; default: System.out.println("a%b="+(a%b)); break; } } }
分支的位置可以自由调整!
分支的内容可以省略!