Home » Java programming language

Java StrictMath pow() Method with Example

StrictMath Class pow() method: Here, we are going to learn about the pow() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 27, 2019

StrictMath Class pow() method

  • pow() method is available in java.lang package.
  • pow() method is used to calculate the power of the given arguments or in other words, it returns the value of the first parameter raised to the power of the second parameter.
  • pow() method is a static method and it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
  • pow() method does not throw any exception at the time of calculating the power of the given arguments.

Syntax:

    public static double pow(double base , double exponent);

Parameter(s):

  • base – represents the base.
  • exponent – represents the power (exponent).

Return value:

The return type of this method is double – it returns the base raised to the power of exponent.

Note:

  • If we pass NaN as the first argument and a non-zero value as the second argument, the method returns NaN.
  • If we pass NaN as the second argument, the method returns NaN.
  • If we pass 1.0 as the second argument, the method returns the value of the first argument.
  • If we pass 0 (native or positive) as the second argument, the method returns 1.0.

Example:

// Java program to demonstrate the example of 
// pow(double base , double exponent) method of StrictMath Class.

public class Pow {
    public static void main(String[] args) {
        // Variable Declarations
        double d1 = 2.0;
        double d2 = 3.0;
        double d3 = 4.0;
        double d4 = 6.0;

        // Here , we will get (d1 raised to the power of d2) 
        // because we are passing parameter (2.0,3.0) 
        System.out.println("StrictMath.pow(d1,d2): " + StrictMath.pow(d1, d2));

        // Here , we will get (d3 raised to the power of d4) 
        // because we are passing parameter (4.0,6.0) 
        System.out.println("StrictMath.pow(d3,d4): " + StrictMath.pow(d3, d4));
    }
}

Output

StrictMath.pow(d1,d2): 8.0
StrictMath.pow(d3,d4): 4096.0


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.