This discussion is archived
8 Replies Latest reply: Dec 1, 2007 9:28 PM by 807603 RSS

Prime Number Programming

807603 Newbie
Currently Being Moderated
Compute all primes less than N, and display the results
step by step on the BlueJ terminal screen to show the working of your program. Upon
completion, you are to summarize the computed results in an easy-to-read format.
The program starts by asking for an integer value N from the user. Print out the initial matrix
of numbers from 2 to N.

To find all primes less than N, you should begin by making a table of integers from 2 to N.
Find the smallest integer i, that is NOT prime and NOT crossed out. Mark i as a prime
number and cross out 2i, 3i, 4i, �, ni N.

When i > N , the algorithm terminates.Screen is cleared once again,
before the program prints the final results in the matrix format.

Following are the requirements for the matrix format:
� The matrix consists of 10 columns
� The number of rows varies, depending on the input N
� Initial matrix: The program prints an empty string in place of 1
� Intermediate matrix: The program prints values for all prime numbers and numbers
that are not crossed out. The program prints an empty string for each crossed-out
� Final matrix: The program prints only the prime numbers less than N

Must implement at least 3 classes for your program. Each of the classes should have
clear and distinct responsibilities associated with it.