program for prime number in java


Founder of Java Engineering Programs. Follow me on Google+ ,Linked in.

You may also like...

Leave a Reply

1 Comment on "program for prime number in java"

Notify of
Sort by:   newest | oldest | most voted

this is the question for pupil…:-)
1. You have to know that it is not necessary to check to 23, rather you have to check to sqrt(23) i.e. to 4. This is simple mathematics.
2. You have to replace while(i<=prime_number-1) with:
int limit = Math.sqrt(prime_number);
3. That is all…:-)