写四个方法:加减乘除
利用循环+switch进行用户交互
传递需要操作的两个数
输出结果
public class Demo05 { public static void main(String[] args) { while (true) { Scanner scanner = new Scanner(System.in); System.out.println("请输入第一个数字:"); int a = scanner.nextInt(); System.out.println("要进行的运算是:"); String s = scanner.next(); System.out.println("请输入第二数"); int b = scanner.nextInt(); // scanner.close(); switch (s) { case "+": System.out.println("结果是:" + add(a, b)); break; case "-": System.out.println("结果是:" + reduce(a, b)); break; case "*": System.out.println("结果是:" + mul(a, b)); break; case "/": System.out.println("结果是:" + div(a, b)); break; } } } public static int add(int a,int b){ return a+b; } public static int reduce(int a,int b){ return a-b; } public static int mul(int a,int b){ return a*b; } public static int div(int a,int b){ return a/b; } }