Practice: Recursion

Take out a piece of paper. We’ll be programming on paper.

Problem 1

Write a method factorial that takes an integer parameter N and returns N!

n!, is the product of all positive integers less than or equal to n.

5! = 5 x 4 x 3 x 2 x 1

Problem 2

Start to write a method

public void printAnagrams(String prefix, String word)

Implement the reducing the problem step for the recursion.

else
  For each letter in the word:
    Print the prefix + letter followed by the rearrangements of the word without the letter.

Focus on building the new prefix and word. The new prefix is the old prefix + letter. The new word is the old word without the letter.

You should use:

Show me your code.