Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: exponent recursion

  1. #1
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Thanked 0 Times in 0 Posts

    Default 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:

    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;
    	      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?

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default 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?

Similar Threads

  1. Recursion
    By qns in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 29th, 2013, 05:04 AM
  2. Recursion Help
    By WeaKeN in forum Algorithms & Recursion
    Replies: 10
    Last Post: May 27th, 2011, 08:17 AM
  3. [SOLVED] Recursion help
    By Actinistia in forum Java Theory & Questions
    Replies: 3
    Last Post: March 21st, 2011, 12:26 PM
  4. Recursion
    By javapenguin in forum Algorithms & Recursion
    Replies: 12
    Last Post: October 18th, 2010, 03:42 PM
  5. Recursion Help
    By vmr in forum Algorithms & Recursion
    Replies: 3
    Last Post: April 1st, 2010, 11:27 PM

Tags for this Thread