Part 1: The program should use a do/while loop to prompt the user for a number...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 ( <2 or> 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). 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 ( <2 or> 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).
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
The following tables summarize the 2022 income statement and end-year balance sheet of Drake's Bowling Alleys. Drake's financial manager forecasts a 15% increase in sales and costs in 2023. The ratio...
-
Define how conflict may be specified in terms of object operation semantics. Give an example of conflicting operations. Give an example of non-conflicting operations that would conflict with...
-
In this question assume that p and q are atomic formulae. (a) Compare and contrast path formulae and state formulae in temporal logic. [4 marks] (b) Describe and contrast the meanings of F(G p) and...
-
9. Write a program to solve function given below, with the x and y value proposed by the user. And, based on the result, show "imaginary result" response for the case of the result of the function is...
-
On the first day of the fiscal year, Shiller Company borrowed $85,000 by giving a seven year, 7% installment note to Soros Bank. The note requires annual payments of $15,772, with the first payment...
-
Craig received a cash distribution of $50,000 in liquidation of half of his one-fourth interest in White Family Partners. His tax basis in his partnership interest prior to the distribution was...
-
Sylvia Heains Catering Service is considering the purchase of new energy-efficient cooking equipment. The cost of the new equipment is \($78,000\). The equipment has an estimated useful life of eight...
-
Marlin Company, a wholesale distributor, has been operating for only a few months. The company sells three productssinks, mirrors, and vanities. Budgeted sales by product and in total for the coming...
-
5. Budgets that are revised by adding a new quarterlybudget to replace the quarter that just elapsed arecalled:A. Production budgets. B. Sales budgets. C. Cash budgets. D.Rolling budgets. E. Capit 2...
-
What effect does increase the required return have on the present value of a future amount and why
-
Given C(x)=10x+3 and R(x) = 50x-0.5x2 Find each of the following a) Total Profit, P(x), b) Total Cost, C (x). Revenue R(x) and Profit P(x) from the production and sale of 40 units c) The Marginal...
-
A boat is stationary at 12 meters away from a dock. The boat then begins to move toward the dock with an acceleration of 5.0 m $2 How long will it take the boat to reach the dock? Your answer should...
-
Concord Company is a leading manufacturer of sunglasses. One of Concord's products protects the eyes from ultraviolet rays. An upscale sporting goods store has contacted Concord about purchasing...
-
Describe the normalization forms and why different normalization forms exist. Should normalization be done on all databases? To what form should databases be normalized?
-
Ivanhoe Corporation issued convertible bonds at a premium of $10400. The $200000 bond issue was convertible into 4400 shares of common stock (par value $20). Two years later, all of the bonds were...
-
You are standing above the point (5, 1) on the surface z = 10 - (2x + y). (a) In which direction should you walk to descend fastest? (Give your answer as a unit 2-vector.) direction = (b) If you...
-
Repeat Exercise 16.6 using the t-test of the coefficient of correlation. Is this result identical to the one you produced in Exercise 16.6?
-
Create a program that tests the class Merlin described in the previous exercise. Use the toString method to verify that a unique instance has been created. Previous exercise. Sometimes we would like...
-
Write a program that manages a list of up to 10 players and their high scores in the computers memory. Use two arrays to manage the list. One array should store the players name and the other array...
-
Write a sequential search of an array of integers, assuming that the array is sorted into ascending order. Consider an array that contains the four integers 2, 4, 6, and 8. How can you tell that 5 is...
-
How much year-end cash should a local government have?
-
You have the following data for a city in the southwest. Calculate the quick ratio. Is this ratio favorable or unfavorable? Current Liabilities. \(\$ 28\) million Cash \(\$ 27\) million Investments...
-
You have the following information about a midwest city. Calculate the ratios of fund balance to revenues and determine if they are favorable or unfavorable. General Fund \(\$ 62\) million Unreserved...
Study smarter with the SolutionInn App