package com.czh;
public class Calculation {
double a;
double b;
public void sum(){
System.out.println(a+b);
}
public void sub(){
System.out.println(a-b);
}
public void mul(){
System.out.println(a*b);
}
public void div(){
if(b!=0){
System.out.println(a/b);
}
else{
System.out.println("无法计算");
}
}
}
package com.czh;
public class Test {
public static void main(String[] args){
Calculation cal = new Calculation();
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("输入a值");
double a = input.nextDouble();
System.out.println("输入b值");
double b = input.nextDouble();
cal.a = a;
cal.b = b;
cal.sum();
cal.sub();
cal.mul();
cal.div();
}
}