Java Practice Assignment #5 – Recursive Factorial

by Trevor Page on February 21, 2013

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:

Click here to Download my Solution

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.

Click here to Download this Assignment

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:

{ 4 comments… read them below or add one }

Leave a Comment

Powered by sweet Captcha

Previous post:

Next post: