Math Class


🙋 Need help? Ask an expert now!

The pow() function of the Math class takes in two double values and returns the result of the first input raised to the power of the second input. The symbol '^' is not used to represent "to the power of" in Java. We can write this function like this: Math.pow(inputOne, inputTwo). Check out the two examples below.
package exlcode;

public class PowerMethodExample {

  public static double exampleVariableOne = Math.pow(10, 2);
  public static double exampleVariableTwo = Math.pow(-10, 2);

  public static void main(String[] args) {

The function of the Math.pow() method mirror the function of exponents we learned in math class. For example, if the second input is zero, the result will always be "1.0" because any number raised to the power of zero is one. Also, if the second input is "1.0", the result with be the first input. If the power function has expressions that use division or any other operation, the expression is evaluated before the power method is run. Because of the previous statement, fractions are not a recommended method for writing your expression. Please be careful of using numbers such as "1/2" because this would result in "0.0", not "0.5".

Edit Me on GitHub!

Application Question

Math.pow(4, 1/2) returns