Recursion Examples from the Morelli Textbook

Make sure you look at both of these examples, and the hints for understanding them inbetween.

Hints for understanding and following both of these, above and below:

- The difference between the two methods is mainly because of the order in which the printing out of the letter and the recursive call are made.

- In the diagram, each lower block is the instance of the method that was called in the block above.

- A method is not finished until you get to (in the diagram) its final semi-colon.

- In recursion, the methods that call other methods recursively are not out of memory until those that it called are finished; they are placed on a stack of unfinished methods.

- It is the interruption of the recursive calls which is the secret to how things work.

- In the code, recall that the charAt() method of the String class prints out the character at a certain element number. So for the String "hello world", charAt(7) would print return 'w'.