India’s Best Job Seekers and Training Platform › Forums › Java Problems set › Square Root
Tagged: Java
-
Write a program to calculate a square root of a number.
-
import java.util.Scanner;
public class SquareRoot {
public static void main(String[]args){
Scanner Scan=new Scanner(System.in);
System.out.println(“Enter the number”);
int n=Scan.nextInt();
double sr=n/2;
double temp;
do{
temp=sr;
sr=(temp+(n/temp))/2;
}while((temp-sr)!=0);
System.out.println(“Square root of the given number is : “+sr);
}
}
Log in to reply.