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: ; i: ; 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!