Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment

Back to Classroom

Power

Java Variables Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Variables Micro Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of understanding regarding Java variables and operators.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

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.

PowerMethodExample.java

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) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
}
}

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".