This week's book giveaway is in the JavaFX forum. We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line! See this thread for details.

You are both mistaken using ½ the number as the limit for testing whether it is prime. You ought to use √number. You also should use a Sieve of Eratosthenes to populate a boolean array and that will tell you whether a number is prime or not. Much faster and efficient than using the % operator. If you look in the Wikipedia article which appears from that link, there is the Sieve of Euler, too.

Andrew Monkhouse
author and jackaroo
Marshal Commander

vinayak jog - thank you for replying, however at CodeRanch we work on the theory that we want to teach people how to solve the problems themselves. Complete solutions don't lend themselves to that - the learning experience is removed.