Java program to find the square root of a number

Hi friends, today I have written a post on how to write a Java program to find the square root of a number.



Java program to find the square root of a number

What is Square Root?
Square root 'p' of a number 'q' is a number such that p2 = q.


    
     import java.util.*;
class Sqroot
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int a;
        double sroot;
        System.out.println("Enter a number");
        a=in.nextInt();
        sroot=Math.sqrt(a);
        System.out.println("The square root of the number is "+sroot);
    }
}
    
  
Output:
Enter a number
4
The square root of the number is 2.0
Hope you enjoyed reading our posts. You may also see other posts related to programming on our website.

Comments

Popular Posts