早教吧 育儿知识 作业答案 考试题库 百科 知识分享

定义一个类,该类具有x和y两个属性,定义构造函数初始化这两个属性.类中还定义以下方法:求两个数的和(x+y)并返回结果的方法,求两个数的差(x-y)并返回结果的方法,求两个数的乘(x*y)并返回结

题目详情
定义一个类,该类具有x和y两个属性,定义构造函数初始化这两个属性.类中还定义以下方法:求两个数的和(x+y)并返回结果的方法,求两个数的差(x-y)并返回结果的方法,求两个数的乘(x*y)并返回结果的方法,求两个数的商(x/y)并返回结果的方法,求两个数的余(x%y)并返回结果的方法,求两个数的最大值并返回结果的方法,求两个数的最小值并返回结果的方法
▼优质解答
答案和解析
public class ClsAAA
{
int x;
int y;
public int X
{
get{return x;}
set{x=value;}
}
public int Y
{
get{return y;}
set{y=value;}
}
public ClsAAA(){
x=0;
y=0;
}
public int GetSum(){
return X+Y;
}
public int GetDiff(){
return X-Y;
}
public int GetMulti(){
return X*Y;
}
public int GetDevi(){
return X/Y;
}
public int GetMod(){
return X%Y;
}
public int GetMax(){
return X>Y?X:Y;
}
public int GetMin(){
return X>Y?Y:X;
}
}