Program that compute prime numbers, JAVA Programming

The purpose of this assignment is to give you practice working with one dimensional arrays. It will also introduce you to one of the oldest mathematical algorithms in the world. Note: It's easy to find Java code for this algorithm on the Internet, but DON'T go looking for it. This is a simple algorithm. You are capable of implementing it yourself, and the purpose of the assignment is for you to do some programming. Feel free to look at the Wikipedia page on the Sieve of Eratosthenes, though.


1.  Write a program that will compute all of the prime numbers up to a specified value in a number of different ways.

  • Your program must have 3 command line arguments. The first gives that value that you want to generate primes to. The second gives the method that the program will use to generate the list of primes. The third argument, if present, tells the program to print out the list of primes, for debug purposes. For example, running the program as follows:

>Primes 100 1 p

should generate an array of numbers such that the elements with prime indices have value 1, and elements with composite indices have value 0. Since there is a 3rd command line argument, the program should print out the list of prime numbers.


  • The methods that you must implement are:

1. Trial division by the numbers up to n

2. Trial division by 2 and the odd numbers up to sqrt(n)

3. Trial division by the primes up to sqrt(n)

4. The sieve or Eratosthenes

Once it has finished, the program should also print out the amount of time that it took to run.

  • Run your program on different sized inputs for the different methods.
  • Write a 1 page report including a table or graph of the results.
  • Turn in your report, your code and class files to the D2L dropbox.

Optional: Optimize your sieve routine so that it uses an array of bits, and only stores the odd numbers in the array. See how high you can go with this optimized sieve. Write about it in your report.

Assignment checklist:

  • Write your program so that it works with command line arguments.
  • Write the 4 different prime finding modes.
  • Make sure the programs compile and run from the command line without modification.
  • Write a 1 page report summarizing the results of running your program in different modes, and for different list sizes.
  • Include your source, executable files and report in your turnin.
  • Zip all of your files in a SINGLE .zip file and turn it in to the D2L dropbox.
Posted Date: 2/19/2013 7:55:21 AM | Location : United States

Related Discussions:- Program that compute prime numbers, Assignment Help, Ask Question on Program that compute prime numbers, Get Answer, Expert's Help, Program that compute prime numbers Discussions

Write discussion on Program that compute prime numbers
Your posts are moderated
Related Questions
What is the difference between instance and object of a class? Few says both are same, then why java kept both the words for same thing?

Normal 0 false false false EN-US X-NONE X-NONE

Question 1 What is Response Redirection? Explain in brief Question 2 What is JDBC? Explain Question 3 Write a short note on Expressions Question 4 What is an XML na

We can get the values in the action classes by using data.getParameter("variable name described in the velocity page");

Want a page to store emails when click as save, then pass along to another page with the emails in the URL Project Description: I have a page that populates with listing; the

The Object class is the highest-level class in the Java class hierarchy. The Class is used to show the classes and interfaces that are loaded by a Java program..

Prepare a Program that can solve OCR Captcha Project Description: I'm seeking someone to develop a program that can solve a php captcha. It should be a web service or scri

write a program to find the area under the curvey y=f(x) between x=a and x=b.integrate y=f(x) between the limits of a and b. the area under a curve between two points can be found

Write JavaScript code that is executed during form submission to calculate the cost of each book (based on quantity specified) and the overall total cost. The results should be dis

i have got project of Vending machine. would you please help me about how to start and how to use coding.thanks