簡單的加減乘除(遞迴)
package method;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//簡易的計算器
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入第一個值:");
double x = scanner.nextDouble();
System.out.println("請輸入第二個值:");
double y = scanner.nextDouble();
System.out.println("請輸入符號:");
String operator = scanner.next();
switch (operator){
case "+":
add(x, y);
System.out.println(x+y);
break;
case "-":
sub(x, y);
System.out.println(x-y);
break;
case "*":
mul(x, y);
System.out.println(x*y);
break;
case "/":
div(x, y);
System.out.println(x/y);
break;
}
}
public static double add(double x,double y){
return x+y;
}
public static double sub(double x,double y){
return x-y;
}
public static double mul(double x,double y){
return x*y;
}
public static double div(double x,double y){
return x/y;
}
}