program for prime number in java

NIRAJ AHER

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
avatar
Sort by:   newest | oldest | most voted
Alex
Guest

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);
while(i<=limit)
3. That is all…:-)

wpDiscuz