java tutorial - Java Math.pow() Method - java programming - learn java- java basics - java for beginners
Learn Java - Java tutorial - Java numbers pow - Java examples - Java programs
Description
The method Math.pow() - raises the value of the first argument to the power of the second argument, thereby allowing a quick raising to the power of any values
Syntax
Options
Detailed information about the parameters:
- base is any primitive data type.
- exponent is any primitive data type.
Return value:
- In Java, Math.pow() returns a double value of the first argument, raised to the power of the second argument.
Example 1: squaring and cube
- To raise any number to a square using the Math.pow() method, use the value 2 for the second argument, and 3 for the cube, and so on. Note that "% .0f" is used to display the integer value, since the method returns a double value.
Output
Example 2: raising a number to a fractional power
Output
Example 3: raising a number to a negative power
Output
Example 4: the erection of a negative number of degrees
- Note that when we raise a negative number to a fractional power, we do not get the result (NaN).