实现实数范围的加减乘除
package com.method;
import java.util.Scanner;
public class zuoYe {
public static void main(String[] args) {
while (true) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数:");
double num1 = sc.nextDouble();
System.out.println("请输入符号");
String operator = sc.next();
System.out.println("请输入第二个数:");
double num2 = sc.nextDouble();
switch (operator) {
case "+":
add(num1, num2);
break;
case "-":
subtract(num1, num2);
break;
case "×":
multiply(num1, num2);
break;
case "/":
divide(num1, num2);
break;
default:
System.out.println("你输入的内容有错请重新输入!");
}
sc.close();
}
}
//加
public static double add(double a,double b){
double result = a + b;
System.out.println(result);
return result;
}
//减
public static double subtract(double a,double b){
double result = a - b;
System.out.println(result);
return result;
}
//乘
public static double multiply(double a,double b){
double result = a * b;
System.out.println(result);
return result;
}
//除
public static double divide ( double a, double b){
double result = a / b;
System.out.println(result);
return result;
}
}