c = ab
‘a’ is called the base, and ‘b’ is called the exponent. The mathematical statement is read as,
c equals ‘a’ raised to the power b.
In Java, ab is an expression, where ‘a’ is the first argument and b is the second argument. In Java, the math statement is:
In the parentheses, ‘a’ is the first argument, and b is the second argument. So, if ‘a’ is 2 and b is 3, then the mathematical meaning is:
c = 2 x 2 x 2
The Math class is in java.lang package. It does not have to be imported manually to be used. The full syntax for the Math.pow method is:
The method is static. This means that pow is used with the class name. The class does not have to be instantiated, into an object, for pow to be used with the object. The two arguments are double, and the return value is double. This article illustrates how to use the Java Math.pow() method.
Base, int and Exponent, int
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The second statement in the main() method prints out c.
Base, float and Exponent, float
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The second statement in the main() method prints out c.
Base, double and Exponent, double
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The second statement in the main() method prints out c.
Base, short and Exponent, short
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The second statement in the main() method prints out c.
Base, long and Exponent, long
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The second statement in the main() method prints out c.
Base, byte and Exponent, byte
Consider the following program:
The output is 8.0. There are two blocks here. The outer block is for the class. The inner block is for the main() method of the class. The first line in the main method declares p and q as bytes. The second statement in the main method is:
The return value must always be declared as a double. If the arguments are not of the double type, they will be converted to double, if possible. The third statement in the main() method prints out c.
Explanation of Math.pow Syntax
The full syntax for the Math.pow method is:
The reserved word, public, means that the method of the class can be accessed from outside the class or class object. The method is static. This means that pow is used with the class name. The class does not have to be instantiated, into an object, for pow to be used with the object. The two arguments are double, and the return value is double.
Conclusion
In the Java expression, math.pow, pow means power. This is related to the math expression,
c = ab
‘a’ is called the base, and ‘b’ is called the exponent. The mathematical statement is read as c equals ‘a’ raised to the power b. In Java, ab is an expression, where ‘a’ is the first argument and b is the second argument. In Java, the math statement becomes:
In the parentheses, ‘a’ is the first argument, and b is the second argument. So, if ‘a’ is 4 and b is 5, then the mathematical meaning is:
c = 4 x 4 x 4 x 4 x 4