# Sqrt Program, skips over method

• July 20th, 2013, 09:23 PM
Lashickk
Sqrt Program, skips over method
Hey guys , I have to do a program where you must find the square root of a number by repeatedly divide a number by the number and past guess untill the diffrence is withing .000001. My code doesnt output , and when it did it would give me 0. If anyoene can help me out itd be much appricated. thanks!

import java.util.*;
import java.lang.Math;
public class sqrt
{
public static void main(String[] args)
{
double value;
double guess;
Scanner in= new Scanner(System.in);
System.out.println("Please enter the number of which you want to squareroot: ");
value=in.nextDouble();
System.out.println("Please enter youre first estimate: ");
guess=in.nextDouble();
while(guess<(value*.5))
{
System.out.print("Please input a higher value: ");
guess=in.nextDouble();
}
System.out.println("The squareroot is: "+ sqrt(value,guess));

}

private static double sqrt(double value, double guess)
{
double nextGuess=guess*2;
while( ((nextGuess-guess)!=.00001)||((nextGuess-guess)!=-.00001) )
{
nextGuess=(guess+(value/guess))/2;
guess=nextGuess;
}
return guess;

}

}
• July 21st, 2013, 01:06 PM
GregBrannon
Re: Sqrt Program, skips over method
Please post your code in code tags.

Your problem statement and description of the problem are not helpful. Here's my sample run:
Code :

```Please enter the number of which you want to squareroot: 51 Please enter youre first estimate: 7 Please input a higher value: 8 Please input a higher value: 8 Please input a higher value: 8 Please input a higher value: 8 Please input a higher value:```
Seems to be running, even outputting, though it's annoying and I have no idea what it's trying to do. Why don't you post a sample run and describe what it should be doing.

Oh, and there's no "skips over method" that I can see.