Groovy - pow()



此方法返回用第二個引數的冪對第一個引數求值。

語法

double pow(double base, double exponent)

引數

  • base - 任意基本資料型別
  • exponent - 任意基本資料型別

返回值

此方法返回值的第一個引數提高到第二個引數的冪。

示例

以下是此方法用法的一個示例 −

class Example {
   static void main(String[] args) {
      double x = 11.635;
      double y = 2.76; 
   
      System.out.printf("The value of e is %.4f%n", Math.E);
      System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));  
   } 
}

當我們執行以上程式時,將獲得以下結果 −

The value of e is 2.7183 
pow(11.635, 2.760) is 874.008
groovy_numbers.htm
廣告
© . All rights reserved.