# exponent recursion

• October 31st, 2013, 12:09 PM
Scorks
exponent recursion
The question is:

The following method was known to the ancient Greeks for computing square roots. Given a value x > 0 and a guess g for the square root, a better guess is (x + g/x) / 2 (g + x/g) / 2. Write a recursive helper method public static squareRootGuess(double x, double g). If g2 is approximately equal to x, return g, otherwise, return squareRootGuess with the better guess. Then write a method public static squareRoot(double x) that uses the helper method.

So, so far I've got:

Code :

```public class main1c {   public static void main(String[] args){   Scanner keys = new Scanner(System.in);     } public static double test(double x, double g) { if (closeEnough(x/g, g)) return g; else return test(g+x/g) }   static boolean closeEnough(double a, double b) { return (Math.abs(a - b) < (b * 0.1)); // a is within 1% of b }   }```

I'm not sure where to go from here. How do I make a recursion method with the equation(g + x/g) / 2?
• October 31st, 2013, 03:45 PM
GregBrannon
Re: exponent recursion
Do you not know how to call another method in your class from the main() method?

What's the purpose of the Scanner object you created? Start with that.

Where did you get the closeEnough() method?