The Artima Developer Community
Sponsored Link

Java Answers Forum
please help me!!!!

3 replies on 1 page. Most recent reply: Nov 16, 2005 12:14 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
rey

Posts: 10
Nickname: zerocoal
Registered: Sep, 2005

please help me!!!! Posted: Nov 14, 2005 9:39 PM
Reply to this message Reply
Advertisement
Write a program that stores the first 400 prime numbers in an array..

Please help me..i dont know how what is the formula of getting the prime numbers...
Thanks a lot..God Bless You all...

I will be expecting your reply...


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: please help me!!!! Posted: Nov 14, 2005 10:45 PM
Reply to this message Reply
There is no real formula for prime numbers, only some rules.

1. All prime numbers except 2 are not even
2. If n1 is NOT a prime number, the result of n1 % [any previous prime number] can be 0.

So:
1. Use a Arraylist<Integer> to store the number. Later this will be very useful to create the array.
2. Put 2 into this list.
3. create a loop

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: please help me!!!! Posted: Nov 16, 2005 12:12 AM
Reply to this message Reply
Well, seems I forgot to complete the answer.
Sorry about that


3. Create a loop from 3 to 400 stepwith 2: for (i = 0; i < 400; i+=2)
4. For every in the list stored prime number (called 'p') except 2 and p <= i / 3:
i is not a prime if the result of i % p == 0.
If this result is not 0 for all the p's, then add i to your ArrayList.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: please help me!!!! Posted: Nov 16, 2005 12:14 AM
Reply to this message Reply
Had an error in the loop code segment.
Here is the right one:
for (i = 3; i <= 400; i+=2)

Flat View: This topic has 3 replies on 1 page
Topic: Transpose matrix Previous Topic   Next Topic Topic: java 3d projections

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use