I'm sure your motives were great, but we don't like people to post ready-made solutions here - particularly in the 'Beginners' forum.
It's much better to guide someone to their own solution. Please read the NotACodeMill (←click) page.
I've kept your original post, and if my colleagues ask me to, I'll restore it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
This sounds like a project Euler question. Is it?
I would suggest you create an array and use a sieve of Eratosthenes to work out whether each number is prime. Then count the primes. 0 and 1 don’t count. Much more effecient than an isPrime method.
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?