Java Math.pow() yöntemi

java.lang.Math.pow() Birinci argümanın değerini ikinci argümanın kuvvetine döndürmek için kullanılır. pow() yönteminin dönüş türü double'dır.

Sözdizimi

 public static double pow(double a, double b)  

Parametre

 a= base b= exponent  

Geri dönmek

Bu yöntem bir değeri döndürür B

  • İkinci argüman olumlu veya olumsuz ise Sıfır , bu yöntem geri dönecektir 1.0 .
  • İkinci argüman bir sayı değilse (NaN) , bu yöntem geri dönecektir NaN .
  • İkinci argüman ise 1 , bu yöntem aşağıdakiyle aynı sonucu döndürecektir. ilk argüman .

örnek 1

 public class PowExample1 { public static void main(String[] args) { double x = 5; double y = 4; //returns 5 power of 4 i.e. 5*5*5*5 System.out.println(Math.pow(x, y)); } }  
Şimdi Test Edin

Çıktı:

 625.0  

Örnek 2

 public class PowExample2 { public static void main(String[] args) { double x = 9.0; double y = -3; //return (9) power of -3 System.out.println(Math.pow(x, y)); } }  
Şimdi Test Edin

Çıktı:

 0.0013717421124828531  

Örnek 3

 public class PowExample3 { public static void main(String[] args) { double x = -765; double y = 0.7; //return NaN System.out.println(Math.pow(x, y)); } }  
Şimdi Test Edin

Çıktı:

 NaN  

Örnek 4

 public class PowExample4 { public static void main(String[] args) { double x = 27.2; double y = 1.0; // Second argument is 1 so output is 27.2 System.out.println(Math.pow(x, y)); } }  
Şimdi Test Edin

Çıktı:

 3.5461138422596736