Back
I want to create a program that calculates the square root of a number without using Math.sqrt
You can do something like this:
public static void calcRoot(){ double num=9; double guess=0; double result=6; while(Math.abs(guess-result)!=0){ guess=result; result=(guess+(num/guess))/2; }System.out.print(result);}
public static void calcRoot(){
double num=9;
double guess=0;
double result=6;
while(Math.abs(guess-result)!=0){
guess=result;
result=(guess+(num/guess))/2;
}
System.out.print(result);
31k questions
32.8k answers
501 comments
693 users