package struct;
import java.util.Scanner;
public class Demo04 {
public static void main(String[] args) {
System.out.println("请输入两个数");
Scanner a = new Scanner(System.in);
int num1 = a.nextInt();
Scanner b = new Scanner(System.in);
int num2 = b.nextInt();
Scanner sc = new Scanner(System.in);
System.out.println("请输入运算符");
String s = sc.nextLine();
switch (s){
case "+":
int sum = sum(num1, num2);
System.out.println("两者的和为:"+sum);
break;
case "-":
int jian = jian(num1, num2);
System.out.println("两者的差为:"+jian);
break;
case "*":
int cheng = cheng(num1, num2);
System.out.println("两者的成为:"+cheng);
break;
case "/":
int chu = chu(num1, num2);
System.out.println("两者的除为:"+chu);
break;
default:
System.out.println("输出错误");
}
a.close();
b.close();
sc.close();
}
public static int sum (int num1,int num2){
int result = 0;
result = num1+num2;
return result;
}
public static int jian (int num1,int num2){
int result = 0;
result = num1-num2;
return result;
}
public static int cheng (int num1,int num2){
int result = 0;
result = num1*num2;
return result;
}
public static int chu (int num1,int num2){
int result = 0;
result = num1/num2;
return result;
}
}
![](https://img2022.cnblogs.com/blog/2145619/202205/2145619-20220528202257907-439401594.png)