طريقة جافا Math.pow()

ال java.lang.Math.pow() يتم استخدامه لإرجاع قيمة الوسيطة الأولى مرفوعة إلى قوة الوسيطة الثانية. نوع الإرجاع لأسلوب pow() مزدوج.

بناء الجملة

 public static double pow(double a, double b)  

معامل

 a= base b= exponent  

يعود

تقوم هذه الطريقة بإرجاع قيمة أ ب

  • إذا كانت الحجة الثانية إيجابية أو سلبية صفر ، ستعود هذه الطريقة 1.0 .
  • إذا كانت الوسيطة الثانية ليست رقما (نان) ، ستعود هذه الطريقة نان .
  • إذا كانت الحجة الثانية 1 ، ستعيد هذه الطريقة النتيجة نفسها كما في الحجة الأولى .

مثال 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)); } }  
اختبره الآن

انتاج:

 625.0  

مثال 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)); } }  
اختبره الآن

انتاج:

 0.0013717421124828531  

مثال 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)); } }  
اختبره الآن

انتاج:

 NaN  

مثال 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)); } }  
اختبره الآن

انتاج:

 3.5461138422596736