Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago