java里如何写x乘y的n次方

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:02:47
前提,必须使用main方法.

使用Math.pow方法

Math.pow(x*y,n);//表示x乘以y后的n次方

补充:
1、定义
1)public static double pow(double a, double b)

Math.pow() 方法包含两个参数。这两个参数包括底数和指数
2)参数
a -- 底数.
b -- 指数
3)返回值
此方法返回 ab.

public static void main(String[] args) {
double r = x * Math.pow(y, n);
}

public class Test{
double result;
int x,y,n;
public static void main(String[] args){
result = a*Math.pow(y,n);
}
}

public class Compute
{
double result;
float x,y;
int n;
public static void main(String[] args)
{
result = a*Math.pow(y,n);
}
}