Question: Part 1: The program should use a do/while loop to prompt the user for a number from 2 to 1000000 (up to 7 digits).

Part 1: The program should use a do/while loop to prompt the

 

Part 1: The program should use a do/while loop to prompt the user for a number from 2 to 1000000 (up to 7 digits). If input is incorrect ( 1000000) the program should display "Incorrect input" and repeat the input process until a valid number is entered. Part 2: The program should use a while loop to determine if the value entered is prime. A prime number is one that is not divisible by any integer in the range 2 through floor(sqrt(number)). For example, to determine if 401 is prime, each potential divisor from 2 through 20 should be checked (the square root of 401 is 20.025). If the value is prime, the program should display " is Prime"; if not, it should display " is Not Prime ( )", where is the first (smallest) divisor that was found. Examples: Enter a number from 2 to 1000000: 1 Incorrect input Enter a number from 2 to 1000000: 29 29 is Prime Enter a number from 2 to 1000000: 40212 40212 is Not Prime (2) Enter a number from 2 to 1000000:-77 Incorrect input Enter a number from 2 to 1000000: 77 77 is Not Prime (7) Notes: You must use the indicated loop type in each step in order to receive credit for this question. The square root of a number can be obtained with the method Math.sqrt(number), e.g., Math.sqrt(2152).

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 Programming Questions!