package com.zhang.Method; import java.util.Scanner; public class counter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num1 = 0; int num2 = 0; int d = 0; System.out.println("请输入第一个要计算的数字:"); num1 = scanner.nextInt(); System.out.println("请输入运算符:"); String a = scanner.next(); System.out.println("请输入第二个要计算的数字:"); num2 = scanner.nextInt(); switch (a){ case "+": d = add(num1,num2); break; case "-": d = subtract(num1,num2); break; case "*": d = multiply(num1,num2); break; case "/": d = divide(num1,num2); break; } System.out.println("结果为:"+d); scanner.close(); } public static int add(int a,int b){ return a+b; } public static int subtract(int a, int b){ return a-b; } public static int multiply(int a, int b){ return a*b; } public static int divide(int a, int b){ return a/b; } }
12-20
771
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)