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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: Problem with fairly basic recursive method

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Problem with fairly basic recursive method

    The point of my code is to find the answer of logbn. I am stuck on the part where a is incremented. I'm not exactly sure where to increment it because every value input will return 1. Any advice? Thanks!
    So here is my code.


    /**
    * Calculates base-b log of n recursively
    * @param b the base of the logarithm to be found
    * @param n the value whose logarithm is being found
    * @return base b log of n
    * Pre-Condition: n must be integer multiple of b
    * @since Lesson 6-4
    * @version 12-6-11
    * @author TFLeGacY
    */
    public int log(int b, int n)
    { int a = 0;
    if(n / b == 1)
    return 1;
    else
    { log(b, n = n / b);
    a++;
    }
    return a;
    }


  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Problem with fairly basic recursive method

    bumpppppppp

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem with fairly basic recursive method

    1) Do not bump your post...for a vast number of reasons it may even affect your chances of receiving help. 2) Do not post your same question twice. I am locking this thread.
    http://www.javaprogrammingforums.com...-you-help.html

Similar Threads

  1. Problem with recursive method. Can you help?
    By TFLeGacY in forum Algorithms & Recursion
    Replies: 6
    Last Post: December 7th, 2011, 05:44 PM
  2. How do I connect 2 method headers to make it recursive???
    By tripline in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 5th, 2011, 05:27 AM
  3. Array code problem Please help fairly easy
    By LOPEZR in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 28th, 2011, 10:51 AM
  4. [SOLVED] StackOverflowError with recursive method
    By samfin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2010, 04:05 PM
  5. Problem with Recursive code
    By Shadow703793 in forum Algorithms & Recursion
    Replies: 4
    Last Post: February 22nd, 2010, 09:36 PM