program for prime number in java

NIRAJ AHER

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

You may also like...

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Alex Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Alex
Guest
Alex

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…:-)