Homework #1: Prime numbers

Problem

The following pseudocode will build an array, a, containing the first n prime numbers:

Set the first element of a to the lowest prime number (2).
For each odd number, test, starting at 3:
    For each element, p, in a:
        Compute the remainder of test/p.
    If the remainder was non-zero for every p:
        Append test to a.
	If the length of a equals n:
		break

Assignment

Create a Java program, Prime.java, to implement this algorithm. The program should accept one command-line argument, the number of primes to generate (n). It should respond by printing the first n prime numbers, followed by a message stating the n-th prime number. If more than 10 prime numbers are requested, the program should print only the first five and the last five, separated by a line displaying an ellipsis ("...").

For example:

$ java Prime 13
   2
   3
   5
   7
   11
   ...
   23
   29
   31
   37
   41
The 13-th prime number is 41.
$

Other requirements:

Due date: The program is due at the beginning of class on 16 September.

Turn in: A listing of your program, and a printout of a terminal session in which you compile the program and run it. You must run the program once with no command-line argument and once for each of the following inputs: 1, 3, 4, 77, and 8000. (Use the Unix script command to record the relevant part of your terminal session.)