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 2 of 2

Thread: Recursion

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Recursion

    Could someone explain to me how this recursion work? Thanks
    ** I understand recursion method with 1 base case but don't understand when it 2 base case.
    x = 4 and the answer is 3 but I don't know how the recursion work. I try to print out what the program is doing but still don't understand. Any help on how this recursion(Equation) work is appreciated.
        public int numFibo(int x)
        {       
            if(x==0)
            {
                return 0;
            }
            else if(x==1)
            {
                return 1;
            }
            else
            {
                return(numFibo(x- 1)+numFibo(x-2));


  2. #2
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Recursion

    What is being passed to the method numFibo? How is that value being manipulated in the code? Try using print statements throughout your code to see how data changes.

    This recursion is made up of 3 basic components the if-statement, returns, and a method. You should look up these components in detail to get a better understanding of how your code is functioning.

    If-statements
    Methods
    Returns

Similar Threads

  1. Recursion Help
    By WeaKeN in forum Algorithms & Recursion
    Replies: 10
    Last Post: May 27th, 2011, 08:17 AM
  2. [SOLVED] Recursion help
    By Actinistia in forum Java Theory & Questions
    Replies: 3
    Last Post: March 21st, 2011, 12:26 PM
  3. Recursion
    By javapenguin in forum Algorithms & Recursion
    Replies: 12
    Last Post: October 18th, 2010, 03:42 PM
  4. Recursion Help
    By vmr in forum Algorithms & Recursion
    Replies: 3
    Last Post: April 1st, 2010, 11:27 PM
  5. Recursion help
    By rhoruns in forum Algorithms & Recursion
    Replies: 4
    Last Post: January 8th, 2010, 11:50 PM