Java Program to find the square root of a number


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


double r = Math.sqrt(n);

Example: How to find the square root of a number in java.

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("Square Root is :" + r);

    }
}

Output:

Enter a number:16
Square Root is :4.0