CoreJava/exp6/Calculator.java
2024-05-09 09:10:51 +08:00

25 lines
631 B
Java

package exp6;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
double a, b;
String opType;
Scanner in =new Scanner(System.in);
System.out.print("请输入第一个数: ");
a = in.nextDouble();
System.out.print("请输入第二个数: ");
b = in.nextDouble();
System.out.print("请选择运算(+-*/): ");
opType = in.next();
in.close();
Operation op = OperationFactory.createOperate(opType);
op.setNumber(a, b);
System.out.println("结果是: "+op.result());
}
}