package bag;
import java.util.Scanner;
public class Demo06 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要操作的选项:1 加法 2 减法 3 乘法 4 除法");
String str = sc.next();
char select=str.charAt(0);
switch (select) {
case '1':
System.out.println("请输入第一个数:");
double a = sc.nextDouble();
System.out.println("请输入第二个数:");
double b = sc.nextDouble();
double sum = add(a, b);
System.out.println("两个数的和为:" + sum);
break;
case '2':
System.out.println("请输入被减数:");
double c = sc.nextDouble();
System.out.println("请输入减数:");
double d = sc.nextDouble();
double difference = subtract(c, d);
System.out.println("两个数的差为:" + difference);
break;
case '3':
System.out.println("请输入第一个数:");
double e = sc.nextDouble();
System.out.println("请输入第二个数:");
double f = sc.nextDouble();
double ride = multiply(e, f);
System.out.println("两个数的积为:" + ride);
break;
case '4':
System.out.println("请输入被除数:");
double g = sc.nextDouble();
System.out.println("请输入除数:");
double h = sc.nextDouble();
double except = divide(g, h);
System.out.println("两个数的商为:" + except);
break;
default:
System.out.println("你的输入有误,请重新输入:");
break;
}
}
public static double add(double a,double b){
return a + b;
}
public static double subtract(double a,double b){
return a - b;
}
public static double multiply(double a,double b){
return a * b;
}
public static double divide(double a,double b){
return a / b;
}
}
标签:java,double,System,sc,计算器,println,加减乘除,nextDouble,out From: https://www.cnblogs.com/lb2410625342/p/17064468.html