Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

I can't figure out the print the 1000th prime number algorithm :(

OpenStudy (woodrow73):

how would you test any random number whether it's prime or not?

OpenStudy (kainui):

I guess the simplest way to do it is make a counter and a while loop to count the number of primes until you've reached the 1000th one. Then inside that while loop you can make a for loop to see if it's divisible by any of the numbers up to half. So for instance, if the current number you're on is 13, then you would have it go through 13%2 13%3 13%4 ... 13% floor(13/2) and % is the syntax in java for mod, so it will just give you the remainder after you subtract the other number multiple times, so 13%5=3. floor just means round down, which is just pseudo code and in java is meaningless if you have already cast 13/2 to an int, it automatically rounds towards 0. of course there are better ways of doing this since obviously you can collect all the primes as you go in a list and only look at those since if it's not divisible by 2 then it is a waste of time to check 4, 6, 8, etc... and then you can stop your while loop when the length of the list is 1000 and read off the last value. So it depends on how sophisticated you want to be.

OpenStudy (anonymous):

I have figured it out thanks for the help I was just tired and being lazy.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
HeyItsAlicia: Mits midnight!!! Happy 16th bday to me !!
40 minutes ago 5 Replies 2 Medals
XShawtyX: Art
3 hours ago 1 Reply 1 Medal
RAVEN69: My drawing so far is actually fire
1 week ago 9 Replies 2 Medals
PureSoulless: is staying at your friend's house while you're homeless legal.
2 weeks ago 5 Replies 1 Medal
whyjustwhy: i did that one TV girl trend with blake (aka @ShadowKid3)
1 week ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!