/*
需求: 简易版计算器
*/
class MyMath{
public double myMathJia(int x,int y){//传入int类型运算时自动提升为double类型
return x + y;
}
public double myMathJian(double x,double y){
return x - y;
}
public double myMathCheng(double x,double y){
return x*y;
}
public double myMathChu(double x,double y){
return x/y;
}
}
// 测试类
class TestMyMath{
public static void main(String[] args){
MyMath m = new MyMath();
double a = m.myMathJia(56,89);
double b = m.myMathJian(56,89);
double c = m.myMathCheng(56,89);
double d = m.myMathChu(56,89);
System.out.println("加法"+a+"减法"+b+"乘法"+c+"除法"+d);
}
}
|
|