Close Scanner:The scanner is closed to free up system resources. Java Code Editor:
You can use a calculator to verify the result: 4! is 4 * 3 * 2 * 1, which results 24. Now let's see how we can calculate factorial using the while loop. Here's our modified method: public static int getFactorialWhileLoop(int n){ int result = 1; while (n > 1) { result =...
# function to calculate the factorial def fact(n): if n == 0: return 1 return n * fact(n - 1) # Main code num = 4 # Factorial print("Factorial of {0} is: {1} ".format(num, fact(num))) OutputThe output of the above program is:Factorial of 4 is: 24 ...