What is Math.sqrt() in Java?
The sqrt() function returns the square root of a double value sent as a parameter.
Figure 1, below, shows the mathematical representation of the sqrt() function.
Syntax
double sqrt(double num)
Parameter
This function requires a double value as a parameter.
Return Value
sqrt() returns the square root of a double value sent as a parameter.
If the argument is
NaNor0, then the function returnsNaN.
Example
class JAVA {public static void main( String args[] ) {//integerSystem.out.println("Math.sqrt(2):");System.out.println(Math.sqrt(2));//perfect square rootSystem.out.println("Math.sqrt(9):");System.out.println(Math.sqrt(9));//negative numberSystem.out.println("Math.sqrt(-4):");System.out.println(Math.sqrt(-4));}}