Question
Factorial.java This is an exercise in using repetition structures to calculate the mathematical values of the factorial function. Since methods have not yet been covered
Factorial.java
This is an exercise in using repetition structures to calculate the mathematical values of the factorial function. Since methods have not yet been covered in detail, you may do the calculations in a class that contains just a main method. The looping structures require the use of count-controlled loops. This program computes the factorial function of a non-negative integer, which is written mathematically as n! (the parameter n followed by an exclamation mark). 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, is defined as: 0! = 1. 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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started