Computer Science, asked by siddharthasingh15, 8 months ago

Wap to find sqrt of a number without sqrt function in Java

Answers

Answered by bala216668
0
import java.util.Scanner;
public class FindSquareRootExample1
{
public static void main(String[] args)
{
System.out.print("Enter a number: ");
//creating object of the Scanner class
Scanner sc = new Scanner(System.in);
//reading a number form the user
int n = sc.nextInt();
//calling the method and prints the result
System.out.println("The square root of "+ n+ " is: "+squareRoot(n));
}
//user-defined method that contains the logic to find the square root
public static double squareRoot(int num)
{
//temporary variable
double t;
double sqrtroot=num/2;
do
{
t=sqrtroot;
sqrtroot=(t+(num/t))/2;
}
while((t-sqrtroot)!= 0);
return sqrtroot;
}
}
Answered by Vyomsingh
1

\large\bf\blue{Question➠}

Wap to find sqrt of a number without sqrt function in Java.

______________________________

\large\bf\green{CODE➠}

class squreroot

{

void main(int n)

{

double squ=Math.pow(n1/2.0);

System.out.println(squ);

}

}

____________________________

Input:-9

Output:- 3.0

Similar questions