在Java中使用Math.pow来获取电源
为了获得Java中数字的幂,我们使用java.lang.Math.pow()方法。Math.pow(doublea,doubleb)方法接受double数据类型的两个参数,然后将第一个参数的值提高为第二个参数的幂。
声明-java.lang.Math.pow()方法的声明如下-
public static double pow(double a, double b)
其中a是基数,b是基数的幂。
让我们看一个程序,使用Math.pow()方法查找数字的幂
示例
import java.lang.Math;
public class Example {
public static void main(String[] args) {
//声明并初始化一些double值
double x = 5.0;
double y = 3.0;
//计算能力
System.out.println( x + " raised to the power of " + y + " is " + Math.pow(x,y));
System.out.println( y + " raised to the power of " + x + " is " + Math.pow(y,x));
}
}输出结果
5.0 raised to the power of 3.0 is 125.0 3.0 raised to the power of 5.0 is 243.0
热门推荐
1 潜能开发训练狗狗
2 狗狗多会训练好
3 扣篮训练狗狗
5 狗狗不训练
6 少儿柔术训练狗狗
8 训练好狗狗
9 训练狗狗怎么训
10 狗狗训练猫咪
11 狗狗训练地点
12 两个多月的狗狗怎么训练
13 怎么训练狗狗去厕所拉屎
14 狗狗怎样训练大小便
15 训练狗狗母
16 怎么训练狗狗坐下和握手
17 近视训练狗狗
18 狗狗倒的训练