import java.util.Scanner;标签:int,System,简易,static,计算器,println,public,out From: https://www.cnblogs.com/123456dh/p/17091641.html
public class Demo08 {
//简易计算器
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数字:");
int firstNum=scanner.nextInt();
System.out.println("请输入运算符号:");
String s=scanner.next();
System.out.println("请输入第二个数字:");
int secondNum=scanner.nextInt();
switch (s){
case "+":
System.out.println(add(firstNum,secondNum));
break;
case "-":
System.out.println(del(firstNum,secondNum));
break;
case "*":
System.out.println(mul(firstNum,secondNum));
break;
case "/":
System.out.println(dm(firstNum,secondNum));
break;
default:
System.out.println("输入有误!");
}
}
//加法
public static int add(int a,int b){
return a+b;
}
//减法
public static int del(int a,int b){
return a-b;
}
//乘法
public static int mul(int a,int b){
return a*b;
}
//除法
public static int dm(int a,int b){
return a/b;
}
}