4. Java Program to find Square Root of a Number.
How does this program work?
- In this programme you will learn about how to do Square Root of a Number using java.
- The following code uses sqrt() mathmetical function.
- And then by using the given logic you will get output.If number is negative, the sqrt function will return a domain error.
Here is the code
//Square root of a number (use sqrt() function)
import java.util.Scanner;public class squareroot
{
public static void main(String args[])
{
int num;
System.out.println("Enter an integer number: ");
Scanner obj=new Scanner(System.in);
num=obj.nextInt();
//Displaying output
System.out.println("Square Root of "+ num + " is:"+ Math.sqrt(num));}
}