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
-
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...
-
Moss Co. issued $42,000,000 of five-year, 11% bonds, with interest payable semiannually, at a market (effective) interest rate of 9%. Determine the present value of the bonds payable using the...
-
Express each expression in simplest form with only positive exponents. 2x3 3 -3
-
After returning from a skiing vacation in Vermont, Leslie Adel came down with Legionnaires Disease. He claimed it was from the water drunk at the ski resort and provided by Greensprings of Vermont...
-
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...
-
3) Lets revisit the 2-D shallow water equations, but this time assume no rotation (f= 0) but the wave is embedded in a mean zonal flow U: V= (U+u'(x, 1)) + v'(x, 1); (1) where variables in bold are...
-
QUESTION 3 YORK Co. Ltd and HERT Plc, are two companies in the electronic car manufacturing sector. Both companies are listed on a major stock exchange in Asia. At the last meeting of its board of...
-
Assume that the risk-free rate is 3 per cent and the expected return on the FTSE 100 index is 9 per cent. The standard deviation of the market index is 23 per cent. You are managing the pension fund...
-
The Dutch firm, ABS Equipment, has an investment opportunity in the United Kingdom. The project costs 12 million and is expected to produce cash flows of 2.7 million in year 1, 3.5 million in year 2,...
-
You are the finance director of a British company which is expecting a payment in euros of 200 million at the end of September and wish to hedge against currency risk. However, the nearest maturity...
-
You plan to raise funds through following Islamic principles. You require funding today of 3 billion Bahrain dinars and would like to pay it back in equal amounts over 10 years in monthly...
-
Suntharee Lhaopadchan is a Thai student who is planning a one-year stay in the United Kingdom. She expects to arrive in the United Kingdom in 8 months. She is worried about depreciation in the Thai...
-
Bill Lawrence has been an employee at Huntington Manufacturing for nearly fifteen years. During this time, he's steadily worked his way up from a frontline worker to management. Plaques and awards...
-
Discuss whether responsible human resources management should apply different standards for the home company and suppliers, for developed countries and developing countries, and for large companies...
-
(a) A photon of energy \(E_{0}\) strikes a free electron at rest in the lab. ("Free" here means the electron is not bound inside an atom.) Is it possible for the photon to be absorbed by the...
-
The quantity \(\lambda_{C} \equiv h / m_{e} c\) is called the "Compton wavelength" of the electron. (a) If a photon scatters off an electron at rest with scattering angle \(\theta=45^{\circ}\), what...
-
The Captain of an interstellar photon-rocket spaceship wishes to maintain a constant acceleration \(a\) in the instantaneous rest-frame of the ship, since that would provide a constant effective...
Study smarter with the SolutionInn App