Question: Purpose This lab gives you some experience writing loops, another very important skill that you will use frequently in programs that you write. Introduction In
Purpose This lab gives you some experience writing loops, another very important skill that you will use frequently in programs that you write. Introduction In this lab, you need to complete an interactive program that reads a non-negative integer n from the user and then do the following parts: - Part 1 Promote the user to enter an integer in the range 010 (including 0 and 10). Write a while loop to validate that the number entered by the user is in this range. If the user enters a number, not in the range, i.e. 20, promote the user to reenter a number in the range. When a user enters a number in the required range, terminate the loop. Reference: Lecture 14, slide 13, the WinPercentage example) - Part 2 Write a while loop to compute the factorial of n (the number entered by the user in the previous step), which is expressed as n ! in Mathematics. The equation to compute n! is: n!=123(n1)n. Then print out the value of nt. Reference: Lecture 14, slides 11.12 , the Average example which computes the rumining sum Hint Note that nt is a notation in Math, there is no such notation in Java, so you need to set up a variable to store the result of nt. Note that 0!=1. For example if the user enters 3 , then 5!=1024345=120, - Par 3 Write a for loop to compute 2f (n is bhe number entered by the use in pan 1). Note that 2n is the product of n2e Then print out the value of 2n For example: if the user inten 3, dirm 25=24262+262=32
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
