package 软件工程;标签:scanner,num2,四则运算,System,break,println,out From: https://www.cnblogs.com/ljsbk/p/17178903.html
import java.util.Scanner;
public class szys {
public static void main(String[] args) {
boolean a=true;
while (a==true) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数字");
double num1 = scanner.nextDouble();
System.out.println("请输入运算符");
String ysf = scanner.next();
System.out.println("请输入另一个数字");
double num2 = scanner.nextDouble();
switch (ysf) {
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("分母为零运算不成立");
break;
} else
System.out.println(num1 / num2);
break;
default:
System.out.println("请输入正确的运算符");
}
System.out.println("输入q即可退出程序,输入其他即可继续程序");
String b=scanner.next();
if (b=="q"){
a=false;
}else {
break;
}
}
}
}