+ 1

How to write a program to find sqaure root of a number without using math library?

5th Aug 2016, 5:31 PM
ASTHA SINGH
ASTHA SINGH - avatar
7 Réponses
+ 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 ;
5th Aug 2016, 6:03 PM
Suhail Pappu
Suhail Pappu - avatar
0
Well buddy the above answer is incorrect
16th Aug 2016, 2:26 PM
raj
raj - avatar
0
then whats the correct one?
19th Aug 2016, 4:22 PM
Aditya Patil
Aditya Patil - avatar
0
I dont know
19th Aug 2016, 4:25 PM
raj
raj - avatar
0
:) ok
19th Aug 2016, 4:31 PM
Aditya Patil
Aditya Patil - avatar
0
Yes you can, Java is just like an calculator, but you need to make the input
17th Oct 2016, 3:29 PM
Finnt730
Finnt730 - avatar
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; } } } }
23rd Nov 2016, 10:42 PM
clucas