Question: Factorial.java This program computes the factorial function of a non-negative integer, which is written mathematically as (n!). Factorial values appear in many important mathematical contexts.

Factorial.java

This program computes the factorial function of a non-negative integer, which is written mathematically as (n!). Factorial values appear in many important mathematical contexts.

For values of n equal to or greater than 1, n! is defined as:

n! = n (n - 1) (n - 2) 1,

and for the value n == 0, the factorial value is defined as:

0! = 1.

For this program, the value computed must be a Java integral value (either int or long ). The program should ask the user for a value, n 0. If the value entered is less than zero, a message must be given the user, and the user allowed to try again. If the value is 0, the program should output the value of 0! and exit. If the value is greater than zero, the factorial value of that value n should be printed (if possible).

The program must then continue to loop and to ask the user for another number for which the factorial may be computed (after each result has been output), until a zero (ending the program) value is entered.

If the user enters a number for which the factorial cannot be computed or cannot be computed correctly, tell the user that is the problem, and keep asking for another number until an acceptable number (or 0) is entered.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!