public class JiSuanQi {
public double num1;
public double num2;
public JiSuanQi(double num1, double num2) {
super();
this.num1 = num1;
this.num2 = num2;
}
public void jia() {
System.out.println("计算结果为:" + (num1 + num2));
}
public void jian() {
System.out.println("计算结果为:" + (num1 - num2));
}
public void cheng() {
System.out.println("计算结果为:" + (num1 *num2));
}
public void chu() {
System.out.println("计算结果为:" + (num1 / num2));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("请输入第一个数字:");
double num1 = sc.nextDouble();
System.out.print("请输入第二个数字:");
double num2 = sc.nextDouble();
System.out.print("请输入符号:");
String fu = sc.next();
JiSuanQi jsq = new JiSuanQi(num1, num2);
switch (fu) {
case "+":
jsq.jia();
break;
case "-":
jsq.jian();
break;
case "*":
jsq.cheng();
break;
case "/":
jsq.chu();
break;
default:
System.out.println("请输入正确符号");
break;
}
}
}