java编写 4的5次方

来源:百度知道 编辑:UC知道 时间:2024/06/16 13:59:40
如题
要完整程序,并简单说明,因为我是菜鸟

Math.pow的方法 就是返回参数一 的参数二次幂的数值

public class Pow {
public static void main(String[] args){
System.out.println(Math.pow(4, 5));
}
}

public class powerAB{
private int dishu;
private int zhishu;
private int result;

//构造函数
public powerAB(int m,int n){
dishu=m;
zhishu=n;
}

//求幂的方法
public void power(){
result=1;
for(int i=1;i<=zhishu;i++)
result*=dishu;
}

//返回结果
public int getResult(){
return result;
}
public static void main(String[] arg){
powerAB mi=new powerAB(4,5);
mi.power();
System.out.print(mi.getResult());
}
}

class chengfang
{
public void main(String[] args)
{
int data = 4;
int counter = 5;
int sum = 0;

sum = theChengFang(data,counter);

System.out.println("4的5次方为:"+sum);
}

public int theChengFang(int num1,int num2)