java math.pow()函数源代码_Java StrictMath pow()用法及代码示例

java.lang.StrictMath.pow()是StrictMath类的一种内置方法,用于查找幂值,即,一个自变量的值升为另一自变量的幂。数学上是指

8534a4f2a1e564c1d12881c80db37c4e.png。它产生三个特殊结果:

当一个参数为NaN而另一个为非零参数或NaN时,该方法返回NaN。

当第二个参数为1.0时,该方法返回与第一个参数相同的值。

当第二个参数为正零或负零时,该方法返回1.0。

用法:

public static double pow(double num1, double num2)

参数:该方法接受两个参数:

num1:这是双精度类型,是指基数。

num2:这是双精度类型,是指 index 。

返回值:该方法返回操作num1^num2的值。

例子:

Input:num1 = 6

num2 = 4

Output:1296.0

Input:num1 = 5

num2 = 2

Output:25.0

下面的程序演示了java.lang.StrictMath.pow()方法:

程序1:

// Java praogram to illustrate the

// java.lang.StrictMath.pow()

import java.lang.*;

public class Geeks {

public static void main(String[] args)

{

double num1 = 12, num2 = 6;

// It returns num1 to the power num2

double pow_Value = StrictMath.pow(num1, num2);

System.out.print(num1 + " to the power of " +

num2 + " = ");

System.out.println(pow_Value);

double pow_Value1 = StrictMath.pow(num1, 0);

double pow_Value2 = StrictMath.pow(num1, 0);

System.out.println(num1+" raised to the"+

" power 0 = " + pow_Value1);

System.out.println(num2+" raised to the"+

" power 0 = " + pow_Value2);

}

}

输出:

12.0 to the power of 6.0 = 2985984.0

12.0 raised to the power 0 = 1.0

6.0 raised to the power 0 = 1.0

程序2:

// Java praogram to illustrate the

// java.lang.StrictMath.pow()

import java.lang.*;

public class Geeks {

public static void main(String[] args)

{

double num1 = 4.7, num2 = 2.5;

// It returns num1 to the power num2

double pow_Value = StrictMath.pow(num1, num2);

System.out.print(num1 + " to the power of " +

num2 + " = ");

System.out.println(pow_Value);

}

}

输出:

4.7 to the power of 2.5 = 47.88997880559147

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值