第1个回答 2021-01-11
public class Test2 {
public static void main(String[] args) {
String a =" ";
do {
Scanner scan = new Scanner(System.in);
System.out.println("请输入第一个数:");
int num1 = scan.nextInt();
System.out.println("请输入第二个数:");
int num2 = scan.nextInt();
System.out.println("请输入运算符:");
String c = scan.next();
switch(c) {
case "+":
System.out.println("运算结果是:"+(num1+num2));
break;
case "-":
System.out.println("运算结果是:"+(num1-num2));
break;
case "*":
System.out.println("运算结果是:"+(num1*num2));
break;
case "/":
if(num2==0) {
System.out.println("除数不能为零,请重新输入");
}else {
System.out.println("运算结果是:"+(num1/num2));
}
break;
}
System.out.println("是否继续? Y 是,其他键结束");
a = scan.next();
}while(a.equals("Y"));
}
}