 <p>This will count the number of primes based on this <a href="http://www.c-sharpcorner.com/blogs/check-a-number-is-prime-number-or-not-in-c-sharp1" rel="nofollow">link</a> and your original answer...</p> <pre><code>public static void main(String[] args) { int isPrimeCount = 0; for(i=0; i&lt;1000; i++) { if(Check_Prime(i)) { isPrimeCount++; } System.out.println(isPrimeCount); } } private static boolean Check_Prime(int number) { int i; for (i = 2; i &lt;= number - 1; i++) { if (number % i == 0) { return false; } } if (i == number) { return true; } return false; } </code></pre>