Ask your own question, for FREE!
Computer Science 36 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
LadyBella: I'm so bored guys any ideas?
16 minutes ago 13 Replies 1 Medal
EdwinJsHispanic: another singing vid, please give me your thoughts on it
12 minutes ago 13 Replies 0 Medals
SwaggyMark: Need help on process of annuity problem
23 hours ago 3 Replies 0 Medals
SwaggyMark: Need guidance on how to solve this annuity problem
1 day ago 25 Replies 1 Medal
Nina001: Tips for acid reflux
23 hours ago 3 Replies 0 Medals
gelphielvr: How would you write Dinitrogen disulfide?
1 day ago 3 Replies 1 Medal
xXAikoXx: What's ethos, pathos, logos?
1 day ago 9 Replies 4 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!