关于加减乘除的问题
package homework;
public class Calculator {
int a;
int b;
double result;
public double sum(){
double sum=a+b;
return result=sum;
}
public double sub(){
double sub=a-b;
return result=sub;
}
public double mult(){
double mult=a*b;
return result=mult;
}
public void div(){
if(b==0){
System.out.println("b!=0");
}else{
double div=a/b;
System.out.println("result="+div);
}
}
public Calculator(int a,int b){
}
}
package homework;
public class CalculatorText {
public static void main(String[] args) {
// TODO Auto-generated method stub
Calculator Calculator1 =new Calculator(3,4);
System.out.println(Calculator1.sum());
System.out.println(Calculator1.sub());
System.out.println(Calculator1.mult());
Calculator1.div();
Calculator Calculator2 =new Calculator(2,1);
System.out.println(Calculator2.sum());
System.out.println(Calculator2.sub());
System.out.println(Calculator2.mult());
Calculator2.div();
}
}
这是两个代码 我做了一个测试类测试。但是算出来的答案不对。