Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: how to fined prime number using arraylist in java

1. ## how to fined prime number using arraylist in java

hi i am having a problem to fined a prime number between 1 to 1000

2. ## 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?

3. ## 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?

4. ## Re: how to fined prime number using arraylist in java

What have you tried?