Java – Math sqrt() Example, Math sqrt() Function

 

Math class is part of java.lang package. Math sqrt method returns the square root value of the argument. If argument value is less than zero, it will return NaN value. sqrt function return type is double or float.

Math sqrt example explains how to use Math sqrt function in java.

public class JavaMathSqrtExample {
    
    public static void main(String[] args) {
        
        double E1 = Math.sqrt(16);
                
        double E2 = Math.sqrt(144.6793);
        
        double E3 = Math.sqrt(-2323.8393);
        
        System.out.println("Math Square root value :"+E1);
        System.out.println("Math Square root value :"+E2);
        System.out.println("Math Square root value :"+E3);
    }
}

Output

Math Square root value :4.0
Math Square root value :12.02827086492485
Math Square root value :NaN

Tags:

 

Leave a Reply