This week's book giveaway is in the Jobs Discussion forum. We're giving away four copies of Soft Skills and have John Sonmez on-line! See this thread for details.

I am trying to write a code for a program that will find the n th prime number.As for example 7 is the 4th prime number,11 is the 5th.
The method will take argument as n,and it will find the nth prime number.But I am facing some difficulty with the code.The code doesnt terminate by itself and doesnt return the desired value.Someone please help me out.

To loop till Integer.MAX_VALUE takes a while I guess. Besides that, this looping is also in a while loop. That calculation would takes ages, and that's why it doesn't stop by itself.

You loop from 0 to Integer.MAX_VALUE without checking the count. You only re-check count after this loop. Merge both loops into one:
This will still loop over i, but this single loop will stop once count == n.

Rob Prime wrote:You loop from 0 to Integer.MAX_VALUE without checking the count. You only re-check count after this loop. Merge both loops into one:
This will still loop over i, but this single loop will stop once count == n.

I modified the code to take into account what you said..
The code compiles,runs and gives the desired output.But I am still facing one odd problem.
I am using Eclipse IDE for coding.Whenever I am trying to run the code,a dialogue box appears that says "Error exists in required project(s).......Proceed with launch?"
What does this mean??

Means there's an error in your current project (or a required one, or something) that doesn't affect the running of the code you're using, or that it does and you've been running the same version of the app without realizing it. Open up the "Problems" tab (view) and see what's there.

I've a comment to make about the ifPrime check: To check divisibility of x, it's not needed to test all numbers from {2 to x} as factors; it's enough to test from {2 to squareroot(x) inclusive}. Take any pair of factors of x, which yield x on multiplication - one of the pair will always be less than or equal to squareroot(x).