写一个计算器,要求实现加减乘除功能,并且能够循环接收新的数据,通过用户交互实现
import Structure.SwitchDemo01;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import java.util.Scanner;
public class HomeWork1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入2个数字:");
double a=scanner.nextDouble();
double b=scanner.nextDouble();
System.out.println("请输入运算符");
String clc = scanner.next();
switch (clc){
case"+":
System.out.println("结果为"+jia(a,b));
break;
case"-":
System.out.println("结果为"+jian(a,b));
break;2
case"*":
System.out.println("结果为"+cheng(a,b));
break;
case"/":
System.out.println(+chu(a,b));
if(b == 0){
System.out.println("被除数不能为0");
break;
}
System.out.println("结果为"+chu(a,b));
break;
default:
System.out.println("输入有误,请重新输入");
}
}
public static double jia(double a,double b)
{
return a+b;
}
public static double jian(double a,double b)
{
return a-b;
}
public static double cheng(double a,double b)
{
return a * b;
}
public static double chu(double a,double b)
{
return a / b;
}
}