• java.lang.Math.pow() method used to find the power of numbers.
  • It is a static method define in Math class so that we can call directly using classname.
  • Math.pow();
  • It takes two double arguments and return type is double.

  1. public final class Math extends Object
  1. public static double pow(double a, double b)



Java Program to explain the usage of Math.pow() method in java

  1. public class MathPow {
  2.  
  3.     /**
  4.      * Math.pow() method in java
  5.      * @author www.instanceofjava.com
  6.      */
  7. public static void main(String[] args) {
  8.     
  9.     
  10.     double a = 3.0;
  11.     double b = 4.0;
  12.  
  13.     
  14.     System.out.println("Math.pow(" + a + "," + b + ")=" + Math.pow(a, b));
  15.     System.out.println("Math.pow(" + b + "," + a + ")=" + Math.pow(b, a));
  16.    
  17.     System.out.println("Math.pow(4,2)="+Math.pow(4,2));
  18. }
  19.  
  20. }

Output:


  1. Math.pow(3.0,4.0)=81.0
  2. Math.pow(4.0,3.0)=64.0
  3. Math.pow(4,2)=16.0
math pow method in java

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu