是有关方法和类的题呢。
完成类MyInteger的定义,并测试。
class MyInteger //自定义整数类
{ private int num; //属性(成员变量)
public MyInteger () { num=0; }
public MyInteger (int x) { num=x; }
//功能:判断当前对象是正数、零、负数
//返回值:1(正数)/0(零)/-1(负数)
public byte IsZero()
{ … }
//功能:获取属性值
public int get_num() { }
//功能:设置当前对象的属性值
//入口参数:设置值
//返回值:无
public void set_num(int a) { num=a; }
//功能:求当前对象的相反数
//返回值:相反数
public ______ opposite_number()
{ }
//功能:判断当前对象是否是素数
//返回值:true/false
public boolean Is_PrimeNumber() { }
//功能:判断当前对象是否是水仙花数(仅判断是三位或四位水仙花数)
//返回值:true/false
public boolean Is_NarcissusNumber() { }
//功能:将当前对象属性的每一位数间隔两个空格输出。即42903à4 2 9 0 3
//返回值:无
public void DisplayDigits()
{ }
//功能:判断当前对象是否是完数
//返回值:true/false
public boolean Is_PerfectionNumber()
{ }
//功能:求当前对象的反序数。即42903à30924
//入口参数:指定对象
//返回值:反序数
public MyInteger antithetical()
{ }
//功能:求当前对象和指定对象的最小公倍数(Least Common Multiple)
//入口参数:指定对象
//返回值:最小公倍数
public MyInteger LCM(MyInteger other)
{ }
//功能:求当前对象和指定对象的最大公约数(greatest common divisor)
/* 定理:***(a,b) = ***(b,a mod b) */
//入口参数:指定对象
//返回值:最大公约数
public MyInteger ***(MyInteger other)
{ int a,b,r;
a=Math.abs(num); b= Math.abs(other.get_num());
if (a<b) { r=a; a=b; b=r; } //保证a>=b
r=a%b; while (r!=0) { a=b; b=r; r=a%b; }
return new MyInteger(b);
}
}
完成类MyInteger的定义,并测试。
class MyInteger //自定义整数类
{ private int num; //属性(成员变量)
public MyInteger () { num=0; }
public MyInteger (int x) { num=x; }
//功能:判断当前对象是正数、零、负数
//返回值:1(正数)/0(零)/-1(负数)
public byte IsZero()
{ … }
//功能:获取属性值
public int get_num() { }
//功能:设置当前对象的属性值
//入口参数:设置值
//返回值:无
public void set_num(int a) { num=a; }
//功能:求当前对象的相反数
//返回值:相反数
public ______ opposite_number()
{ }
//功能:判断当前对象是否是素数
//返回值:true/false
public boolean Is_PrimeNumber() { }
//功能:判断当前对象是否是水仙花数(仅判断是三位或四位水仙花数)
//返回值:true/false
public boolean Is_NarcissusNumber() { }
//功能:将当前对象属性的每一位数间隔两个空格输出。即42903à4 2 9 0 3
//返回值:无
public void DisplayDigits()
{ }
//功能:判断当前对象是否是完数
//返回值:true/false
public boolean Is_PerfectionNumber()
{ }
//功能:求当前对象的反序数。即42903à30924
//入口参数:指定对象
//返回值:反序数
public MyInteger antithetical()
{ }
//功能:求当前对象和指定对象的最小公倍数(Least Common Multiple)
//入口参数:指定对象
//返回值:最小公倍数
public MyInteger LCM(MyInteger other)
{ }
//功能:求当前对象和指定对象的最大公约数(greatest common divisor)
/* 定理:***(a,b) = ***(b,a mod b) */
//入口参数:指定对象
//返回值:最大公约数
public MyInteger ***(MyInteger other)
{ int a,b,r;
a=Math.abs(num); b= Math.abs(other.get_num());
if (a<b) { r=a; a=b; b=r; } //保证a>=b
r=a%b; while (r!=0) { a=b; b=r; r=a%b; }
return new MyInteger(b);
}
}