Factorial

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Perhaps you should run the program to find out.

Factorial

Here is the definition of N factorial:

N Factorial == N! == N * (N-1) * (N-2) * (N-3) * . . . 4 * 3 * 2 * 1

N must be a positive integer or zero, and 0! is defined to be 1. For example,

 
6! == 6 * 5 * 4 * 3 * 2 * 1 == 720

Let us write a program that computes N! . The program checks that N is positive or zero, then computes the factorial.

QUESTION 8:

Say that the user enters a 5. How can the program generate the integers 5, 4, 3, 2, and 1 that are to be multiplied?