I can't figure out the print the 1000th prime number algorithm :(
how would you test any random number whether it's prime or not?
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.
I have figured it out thanks for the help I was just tired and being lazy.
Join our real-time social learning platform and learn together with your friends!