Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer in Java To reinforce the use of strange and for loops. Assignment Write a program that reads in an integer greater than 1 in

Answer in Java image text in transcribed
To reinforce the use of "strange" and for loops. Assignment Write a program that reads in an integer greater than 1 in from the user. The program then computes and print out the factorial of the number read in. The factorial of a number is the product of all the natural numbers less than or equal to the number itself. That is the factorial of n is 1*2*3* ... (n - 2)*(n - 1)*n. Your program should stop if the user enters a negative number. Design You will probably want to make a class called Integer which has a single instance variable of class int. This class would also have an accessor method for the value and a method factorial, which will compute the factorial. This separates the input and output from the computation. Sample Output Enter a number: 5 The factorial of 5 is 120. Enter a number: 8 The factorial of 8 is 40320. Enter a number: 12 The factorial of 12 is 479001600. Enter a number: -1 Thank you and bye

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions