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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how to fined prime number using arraylist in java

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to fined prime number using arraylist in java

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. determining a prime number
    By ob7ivion in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 14th, 2013, 09:27 AM
  2. Prime number solver.
    By Danny123 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: June 4th, 2012, 05:30 AM
  3. display all prime factors of a number
    By mia_tech in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 18th, 2012, 06:55 PM
  4. Prime Number Code Help!
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 7th, 2012, 12:07 AM
  5. Prime Number Program for class
    By chachunga in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 22nd, 2011, 12:05 AM