how to fined prime number using arraylist in java

• April 18th, 2013, 10:08 AM
sharma605
how to fined prime number using arraylist in java
hi i am having a problem to fined a prime number between 1 to 1000
• April 18th, 2013, 10:19 AM
Norm
Re: how to fined prime number using arraylist in java
Can you explain what problems you are having? Post the code you are having problems with.
What does using an arraylist have to do with the problem?
• April 18th, 2013, 10:22 AM
sharma605
Re: how to fined prime number using arraylist in java
Implement the sieve of Erathostenes: a method for computing prime numbers, known to the ancient Greeks. This method will compute all prime numbers up to n. For your implementation, choose an n of 1000. Here is how you do it:

First insert all numbers from 2 to n into a set.
Erase all multiples of 2 (except 2); that is, 4, 6, 8, 10, 12...n
Erase all multiples of 3: that is, 6, 9, 10, 12....n
Repeat for all multiples up to the square root of n.
Print the numbers remaining in the set -- these are the prime numbers
You'll want to look up the methods on Set in the javadoc. Think carefully of what type of Set you will use -- is a TreeSet or a HashSet more appropriate?
• April 18th, 2013, 10:26 AM
Norm
Re: how to fined prime number using arraylist in java