Discuss the below:
Q: Create a program that takes a value x as input and outputs this sum for n taken to be each of the values 1 to 10, 50, and 100. Your program should repeat the calculation for new values of x until the user says she or he is through. The expression n! is called the factorial of n and is defined as
n! = 1 * 2 * 3 * ... * n
Define variables for the value of n! in the current iteration of the loop. Within the loop, you can then simply update this variable to be equal to the previous value multiplied by the value of the loop iterator. For example, if the loop iterator variable is n and the current factorial value is in variable fact, the following line will update the value of the factorial:
fact = fact * n;
The program should use a DecimalFormat object (local variable nFormat) to format the output. See Section 2.1 for more information on the DecimalFormat class.