Java Program to find square root of a number


In this program, You will learn how to find square root of a number in Java.


double r = Math.sqrt(n);


Example: How to find square root of a number in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        double n, r;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a Number :");
        n = sc.nextDouble();

        r = Math.sqrt(n);
        System.out.println("\nThe Square Root is :" + r);

    }
}

Output:

Enter a Number :16
The Square Root is :4.0