Question: te a program in java that does the following: Exercise 3: Wri 1. It prompts the user for an integer 2. It calculates the factorial

te a program in java that does the following: Exercise 3: Wri 1. It prompts the user for an integer 2. It calculates the factorial of that integer in another method (public double factorial(int n)). Observe that the factorial of an integer n is given by: factorial(n) = n (n-1 )(n-2). . . 3.2 1 For example factorial (4) 4.3.2.1-24 By definition, factorial(0)-1 3. The resulting factorial is printed in the main method: A sample output session is: Enter an integer: 5 The factorial of 5 is 120 l exceptions could be thrown in this p (a) if the user enters a non-integer (for example 3.5) (b) if the user enters a negative integer (factorials of negative integers are not defined) (c) if the user enters an integer whose factorial is too large to fit in the range int. 4. Severa rocess (Typically java's primitive type int cannot calculate factorial(14) or higher correctly). 5. Use java's built-in exceptions and/or user defined exceptions to catch an exception and print an appropriate message for each one of the above cases separately repeatedly asks for user input until the user enters a valid input. The program then prints the factorial of the input. . Make sure the program A sample output session is: Enter an integer: 3.5 Exception: You entered a non-integer Enter an integer: -3 Exception: You entered a negative integer Enter an integer: 20 Exception: factorial (20) is too 1arge for int data type Enter an integer: 7 The factorial of 7 is 5040 Process Completed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
