As always, I’ll include my solution to the previous assignment before I give you the requirements for the next assignment. Here’s my video walk-through of assignment 4:
Recursive Factorial Assignment
Since you have now learned about recursion in Java, now it’s time to put that knowledge to the test! Your job will be to implement a recursive method that will be able to calculate any given number’s factorial.
First off, if you don’t know what a factorial is, allow me to explain. A factorial is a calculation based on multiplying a given number by it’s decrementing values until you reach the number 1. The notation for this is a given number following by an exclamation mark. Let’s look at some examples, as they will make this explanation make sense:
2! = 2 x 1 = 2 3! = 3 x 2 x 1 = 6 4! = 4 x 3 x 2 x 1 = 24 5! = 5 x 4 x 3 x 2 x 1 = 120 6! = 6 x 5 x 4 x 3 x 2 x 1 = 720
Does that make sense to you? All we do is take the original number and then multiply it by the number lower than it by 1… rinse and repeat until we get to 1.
So if you remember the important aspects of a recursive algorithm, you’ll remember that you must have an ending point, and a constant progression towards that ending point.
Explanation of How to Setup this Assignment
Here’s a quick video that will walk you through how to setup this assignment on your computer:Google+