A prime number is a whole number which has only two divisors, I and itself. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A prime number is a whole number which has only two divisors, I and itself. The simplest way to test primality of a number is to keep dividing it by prime numbers that are smaller than or equal to the floor of its square root. If the number is not divisible with any of those primes, it is a prime itself, otherwise it is not a prime. For instance, to test whether 23 is prime, you need to have the list of all prime numbers smaller than or equal to the floor of the square root of 29, i.e. 5, which are 2, 3 and 5 (Note that the square root of 29 is 5.3851 so its floor is 5). Since 29 is not divisible by 2, 3 or 5, it is prime. To do the primality test for 63, we first need to find all prime numbers that are smaller than or equal to the floor of the square root of 63 (i.e. 7), which an 2,3,5 and 7. We know that 3 divides 63 and therefore 63 is not a prime. To check whether a divides b, we can just see if the remainder of b divides by a is zero. In Java, we can simply check condition ba=0. For this assignment, you need to write a program called PrimeFinder that takes two whole numbers on the command line that are greater than 0 and smaller than 1,000,001 and finds all prime numbers between the two numbers (both inclusive) and then prints them on the screen once all those numbers have been found. Note that you should not print the primes as you find them. First, find all of them and then print them out. Note: • The second number supplied on the command line must be greater than or equal to the first number. • Testing your program with very large number might take a long time, so try to test it with smaller numbers. • As always, validate user's input and print an appropriate error message if there's something wrong. • Use arrays to store the primes. You may need to use more than one array depending on how you code your program. Examples: $ java PrimeFinder 2 2 2 $ java PrimeFinder 7.001 30.50 11, 13, 17, 19, 23, 29 $ java PrimeFinder 32 21 Error: max must be greater than or equal to min. $ java PrimeFinder 2 Error: Wrong number of arguments Usage: PrimeFinder <min> <max> $ java PrimeFinder 20 x Error: max must be a number $ java PrimeFinder -20 20 Error: min must be between 0 and 1,000,000. Activate Windows Go to Settings to activate A prime number is a whole number which has only two divisors, I and itself. The simplest way to test primality of a number is to keep dividing it by prime numbers that are smaller than or equal to the floor of its square root. If the number is not divisible with any of those primes, it is a prime itself, otherwise it is not a prime. For instance, to test whether 23 is prime, you need to have the list of all prime numbers smaller than or equal to the floor of the square root of 29, i.e. 5, which are 2, 3 and 5 (Note that the square root of 29 is 5.3851 so its floor is 5). Since 29 is not divisible by 2, 3 or 5, it is prime. To do the primality test for 63, we first need to find all prime numbers that are smaller than or equal to the floor of the square root of 63 (i.e. 7), which an 2,3,5 and 7. We know that 3 divides 63 and therefore 63 is not a prime. To check whether a divides b, we can just see if the remainder of b divides by a is zero. In Java, we can simply check condition ba=0. For this assignment, you need to write a program called PrimeFinder that takes two whole numbers on the command line that are greater than 0 and smaller than 1,000,001 and finds all prime numbers between the two numbers (both inclusive) and then prints them on the screen once all those numbers have been found. Note that you should not print the primes as you find them. First, find all of them and then print them out. Note: • The second number supplied on the command line must be greater than or equal to the first number. • Testing your program with very large number might take a long time, so try to test it with smaller numbers. • As always, validate user's input and print an appropriate error message if there's something wrong. • Use arrays to store the primes. You may need to use more than one array depending on how you code your program. Examples: $ java PrimeFinder 2 2 2 $ java PrimeFinder 7.001 30.50 11, 13, 17, 19, 23, 29 $ java PrimeFinder 32 21 Error: max must be greater than or equal to min. $ java PrimeFinder 2 Error: Wrong number of arguments Usage: PrimeFinder <min> <max> $ java PrimeFinder 20 x Error: max must be a number $ java PrimeFinder -20 20 Error: min must be between 0 and 1,000,000. Activate Windows Go to Settings to activate
Expert Answer:
Answer rating: 100% (QA)
Java public class PrimeFinder public static void mainString ar... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
This question concerns lexical grammars. (a) Tree Adjoining Grammars contain two types of elementary tree. (i) What are these trees called? [1 mark] (ii) If one were building a grammar for English...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Write a program that takes the name of an image file as a command-line argument, and creates and shows three Picture objects, one that contains only the red components, one for green, and one for...
-
What benefits have Mexico's regional trade agreements had on the country's economy?
-
The daily selling price per 100 pounds of buffalo meat is normally distributed with a mean of $70, and the probability that the daily price is less than $85 is 0.9332. Four days are chosen at random....
-
In an electric breakdown in air (a spark), an electron (inertia \(9.11 \times 10^{-31} \mathrm{~kg}\) ) experiences an electric force of \(4.83 \times 10^{-13} \mathrm{~N}\). What is the magnitude of...
-
The following transactions apply to Ozark Sales for 2018: 1. The business was started when the company received $50,000 from the issue of common stock. 2. Purchased equipment inventory of $380,000 on...
-
Discuss the linkage between strategic planning and budgeting for your first budget year. Provide at least two examples with details on how you will link your budget to your care-delivery strategy in...
-
Elton Company manufactures wheel rims. The controller expects the following ABC allocation rates for 2018: (Click the icon to view the allocation rates.) Elton produces two wheel rim models: standard...
-
Discuss how effectively logos were used in The Cove. This means you will discuss the various claims the movie made and what evidence was provided to support those claims. Was this done effectively?...
-
Assuming an interest rate of 2.25% per annum, a monthly compounding period, and the following account information for the month of June 2022, find the amount of interest that will be credited to the...
-
Discuss the emergence of the supply chain management concept. Discuss how the logistics function contributes to the supply chain management processes established in the SCOR and GSCF models. Briefly,...
-
a. b. C. Suppose that a simple regression has quantities (y - y)=631.63 and Ze = 182.85. Find R. Interpret the result for R. [15 marks] Suppose that a simple regression has quantities N = 20,...
-
Discuss the organizational strategy that the Oakland A's employed in the movie. Discuss 1 pro and 1 con of the main strategy by Billy Beane. Are the so called "geeks", like Pater Brand going to...
-
A borrower is making a choice between a mortgage with monthly payments or biweekly payments. The loan will be $226,000 at 6 percent interest for 20 years. Required: a. hat would be the maturity...
-
Bank X has 8 subprime mortgage loans to sell to investors. X is supposed to receive $100 as the principal + interest by each borrower. However, many borrowers are low-credit ones, so the true values...
-
Avatar Financials, Inc., located on Madison Avenue, New York City, is a company that provides financial advice to individuals and small- to mid-sized businesses. Its primary operations are in wealth...
-
School district information was examined for a random selection of states. The data below show the number of elementary schools and the number of secondary schools for each particular state. Is there...
-
A random sample of 50 four-year-olds attending day care centers provided a yearly tuition average of $3987 and the population standard deviation of $630. Find the 90% confidence interval of the true...
-
A gardening company is testing new ways to improve plant growth. Twelve plants are randomly selected and exposed to a combination of two factors, a Grow-light in two different strengths and a plant...
-
Scuba divers are warned that if they must make a rapid ascent, they should exhale on the way up. If a diver rapidly ascends to the surface with lungs full of air, his lungs could be damaged. Explain...
-
A higher level of hemoglobin in the blood increases the bloods density. This is the basis for a simple test that can be used to see if a prospective blood donor has a high enough hemoglobin level to...
-
Elephant seals do deep dives to forage for food. The energy used by the seals in diving depends on their body composition; for example, fatter seals use less energy to swim to the surface at the end...
Study smarter with the SolutionInn App