當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.lang.StrictMath.pow()用法及代碼示例


描述

這個java.lang.StrictMath.pow() 方法返回第一個參數的值的第二個參數的冪。它包括這些情況 -

  • 如果第二個參數是正零或負零,則返回 1.0。
  • 如果第二個參數為 1.0,則返回與第一個參數相同的值。
  • 如果第二個參數是 NaN,則返回 NaN。
  • 如果第一個參數是 NaN 而第二個參數不為零,則返回 NaN。

聲明

以下是聲明java.lang.StrictMath.pow()方法

public static double pow(double a, double b)

參數

  • a- 這是基礎

  • b- 這是 index 值。

返回值

此方法返回值 ab

異常

NA

示例

下麵的例子展示了 java.lang.StrictMath.pow() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      double d1 = 4.5 , d2 = 6.9, d3 = 1;
   
      // returns d1 to the power d2
      double powValue = StrictMath.pow(d1 , d2); 
      System.out.println(""+ d1 + " to the power of " + d2 + " = " + powValue);

      // returns d1 to the power d3
      powValue = StrictMath.pow(d1 , d3); 
      System.out.println(""+ d1 + " to the power of " + d3 + " = " + powValue);
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

4.5 to the power of 6.9 = 32148.916823357664
4.5 to the power of 1.0 = 4.5

相關用法


注:本文由純淨天空篩選整理自 Java.lang.StrictMath.pow() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。