Write a Java Program to Find the Square root of a Number using Math.sqrt and without using the sqrt function with example.
Java Program to Find Square Root of a Number Example
This program allows the user to enter integer values and then find the square root of that number using the math function Math.sqrt. Refer to the Java math.sqrt.
import java.util.Scanner;
public class SqrtofNumber1 {
private static Scanner sc;
public static void main(String[] args)
{
double number, squareRoot;
sc = new Scanner(System.in);
System.out.print(" Please Enter any Number : ");
number = sc.nextDouble();
squareRoot = Math.sqrt(number);
System.out.println("\n The Square of a Given Number " + number + " = " + squareRoot);
}
}

Find the Square root of a Number Example 2
In this Java Program, we are using the Java pow math function to find the square root of a number. As we all know √number = number½
import java.util.Scanner;
public class SqrtofNumber2 {
private static Scanner sc;
public static void main(String[] args)
{
double number, squareRoot;
sc = new Scanner(System.in);
System.out.print(" Please Enter any Number : ");
number = sc.nextDouble();
squareRoot = Math.pow(number, 0.5);
System.out.println("\n The Square of a Given Number " + number + " = " + squareRoot);
}
}
Please Enter any Number : 625
The Square of a Given Number 625.0 = 25.0
Also visit