OneCompiler

find square root of a given positive integer. If it is not a perfect square, compute the square root to a precision of 3 digits after decimal point. (Without predifned function)

173
```java
 
 
import java.util.Scanner;

public class Problem_03 {

	public static void main(String[] args) {
	
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter Number :");
		int x=sc.nextInt();
		
		System.out.printf("%.3f",squareRoot(x));
		
	}

	private static double squareRoot(int x) {
		double temp;  
		double sqrroot=x/2;  
		do   
		{  
		temp=sqrroot;  
		sqrroot=(temp+(x/temp))/2;  
		}   
		while((temp-sqrroot)!= 0);  
		
		return sqrroot;
	}

}