定义一个接口,再定义类实现该接口,编写应用程序,调用接口中的 3 个方法,并将调用方法所得的结果输出。

/**
 * 定义一个接口,接口中有 3 个抽象方法如下。
(1)“long fact(int m);”方法的功能为求参数的阶乘。
(2)“long intPower(int m,int n);”方法的功能为求参数 m 的 n 次方。
(3)“boolean findFactor(int m,int n);”方法的功能为判断参数 m 加上参数 n 的和是否大
于100。
定义类实现该接口,编写应用程序,调用接口中的 3 个方法,并将调用方法所得的结果输出。
 * @author Chenkunqing
 *time:2017/7/26/21:00
 */
interface MathInterface{
long fact(int m);
long intPower(int m,int n);
boolean findFactor(int m,int n);
}


class MathInter implements MathInterface {
/**
* 方法的功能为求参数的阶乘。
* @author Chenkunqing
*
*/
public long fact(int m){
int sum =1;
for(int i=1 ;i<=m;i++){
sum *=i;
}
return sum;
//定一个数用于存储结果。

};
/**
* 方法的功能为求参数 m 的 n 次方。
* @author Chenkunqing
*
*/
public long intPower(int m,int n){
int cj=1;
for(int i=0;i<n;i++){
cj=(int) Math.pow(m,n); 
//求一个数,如m的n次方
}
return cj;

};
/**
* 方法的功能为判断参数 m 加上参数 n 的和是否大于100。
* @author Chenkunqing
*
*/
public boolean findFactor(int m,int n){
if((m+n)>100){
return true;
}else{
return false;
}
//如果是真的大于就返回true,反之,不是返回false。
};


}
public class TestInterface {


public static void main(String[] args) {
// TODO Auto-generated method stub
MathInter mi=new MathInter();
mi.fact(10);
mi.findFactor(30, 80);
mi.intPower(2, 3);
System.out.println(mi.fact(10));
System.out.println(mi.findFactor(30, 80));
System.out.println(mi.intPower(5, 3));
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值