Question
1) Write a function fact (n) which returns factorial of integer n using a for loop . This function needs to be used by the
1) Write a function fact (n) which returns factorial of integer n using a for loop. This function needs to be used by the program in Part 2 of this assignment.
2) Write a program in Java that does the following: -Prompts the user of the program to enter an integer (in decimal system) or enter "Quit". -Reads a string from the keyboard. -If the entered string is "Quit", it terminates the program, otherwise, it does the following:
.Calls function fact (n) (written in Pat #1) and prints the value returned by the function. -Repeats the above (if it did not quit).
*Hints(s): 1) for loop syntax:
for (i:
e.g. for (i = 0; i < n; i++) //Start i at 0, increment i by 1 for next iteration, and
//keep looping/repeating as long as i is less than n
sh-4.3$ java A3 Enter an integer [or Quit to end the program]: 3 Factorial of 3 is 6 Enter an integer [or Quit to end the program]: 4 Factorial of 4 is 24 Enter an integer [or Quit to end the program]: Quit sh-4.3$
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