实现功能:
1.可以循环进行计算
2.按q或者Q退出
3.除数为零时提示
import java.util.Scanner;
public class SuccSwitch {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double r = 0;
String q = "m";
Scanner en = new Scanner(System.in);
while(!q.equals("q") && !q.equals("Q")){
boolean flag = true;
System.out.print("input a op b: ");
double a = sc.nextDouble();
String f = sc.next();
double b = sc.nextDouble();
switch(f){
case "+":r = a+b;break;
case "-":r = a-b;break;
case "*":r = a*b;break;
case "/":
if(b == 0){
System.out.println("can not be zero");
flag = false;
}
else{
r = a/b;break;
}
break;
default:
System.out.println(" no guifan ");
flag = false;
}
if(flag){
System.out.println("r is " + r);
}
Scanner input = new Scanner(System.in);
System.out.print("use q or Q quit, an ren yi zi fu continue >>> ");
String p = input.next();
q = p;
}
System.out.println("bye bye");
}
}