+ 1
How to write a program to find sqaure root of a number without using math library?
7 ответов
+ 6
public static double sqrt ( int number ) {
double t ;
double squareRoot = number / 2;
do {
t = squareRoot ;
squareRoot = ( t + ( number / t )) / 2;
} while (( t - squareRoot ) != 0 ) ;
return squareRoot ;
0
Well buddy the above answer is incorrect
0
then whats the correct one?
0
I dont know
0
:) ok
0
Yes you can, Java is just like an calculator, but you need to make the input
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
int num2 = num.nextInt();
int max = num2/2;
for (int i=1;i<=max;i++) {
if(i*i==num2){
System.out.println(i);
break;
}
}
}
}