package method;
import java.util.Scanner;
public class Demo06 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
//无限for循环
for(;;) {
System.out.println("输入两个数:");
int a=scanner.nextInt();
int b=scanner.nextInt();
//输入字符
char c=scanner.next().charAt(0);
char d=c;
switch (d) {
case ‘+‘:
add(a, b);
System.out.println(a + b);
break;
case ‘-‘:
dim(a, b);
System.out.println(a - b);
break;
case ‘*‘:
mul(a, b);
System.out.println(a * b);
break;
case ‘/‘:
div(a, b);
System.out.println(a / b);
break;
}
}
}
//加法方法
public static int add(int a,int b){
return a+b;
}
//减法方法
public static int dim(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;
}
}
原文:https://www.cnblogs.com/bronya187/p/14727471.html