- 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.
- public final class Math extends Object
- public static double pow(double a, double b)
Java Program to explain the usage of Math.pow() method in java
- public class MathPow {
- /**
- * Math.pow() method in java
- * @author www.instanceofjava.com
- */
- public static void main(String[] args) {
- double a = 3.0;
- double b = 4.0;
- System.out.println("Math.pow(" + a + "," + b + ")=" + Math.pow(a, b));
- System.out.println("Math.pow(" + b + "," + a + ")=" + Math.pow(b, a));
- System.out.println("Math.pow(4,2)="+Math.pow(4,2));
- }
- }
Output:
- Math.pow(3.0,4.0)=81.0
- Math.pow(4.0,3.0)=64.0
- Math.pow(4,2)=16.0
No comments