Java-lang-strictmath-pow

提供:Dev Guides
移動先:案内検索

Java.lang.StrictMath.pow()メソッド

説明

  • java.lang.StrictMath.pow()*メソッドは、最初の引数の値を2番目の引数の累乗に戻します。それはこれらのケースを含みます-
  • 2番目の引数が正または負のゼロの場合、1.0を返します。
  • 2番目の引数が1.0の場合、最初の引数と同じ値を返します。
  • 2番目の引数がNaNの場合、NaNを返します。
  • 最初の引数がNaNで、2番目の引数がゼロ以外の場合、NaNを返します。

宣言

以下は* java.lang.StrictMath.pow()*メソッドの宣言です

public static double pow(double a, double b)

パラメーター

  • a -これはベースです
  • b -これは指数値です。

戻り値

このメソッドは、値a ^ b ^を返します。

例外

NA

次の例は、java.lang.StrictMath.pow()メソッドの使用方法を示しています。

package com.finddevguides;

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