CMIS 141
Lab 3
Primes
Write a program to find all the prime numbers from 2 up to a
user-specified number.
A prime number is a positive integer that is (evenly) divisible only
by itself and 1, no other integer evenly divides it.
2 3 5 7 11 13 17 19 23 ... are the first few prime numbers.
Here's pseudo-code to do this:
loop: i from 2 to endnumber //test each integer in the range
loop: j from 2 to i-1 //each possible divisor
if j divides i (i%j==0 no remainder when divide i by j)
i is not prime. set a variable to indicate so.
(This algorithm can be made much more efficient but we'll do that
later.)
Display the found primes in a scrollable textarea if the user so
desires (use a JOptionPane.showConfirmDialog to get the user's
desire).
Use existing code such as CoinFlip2 and modify it for all the various
incantations to get these working; no need to reinvent the wheel.
It's easier to delete a ton of stuff than type new stuff.
Display the number of prime numbers determined in the status bar as
they are being determined (a running count of the prime numbers found
so far as the program runs).
See the prime applet at the class web site for what is wanted.
Done already?
make the code more efficient.