Only ODD numbers can be prime, so we should only be checking those numbers. You also need to break from your inner loop once you realize the number is not a prime. No need to keep checking it, since once a number is not prime, there is no further test that could overrule that decision.
Code:
Also, if you are allowed to, a FOR loop is better than a WHILE loop in that instance, as it makes for cleaner code.
Code:
Code:
count = num1 | 1; // Make sure count is ODD
while(count <= num2)
{
bool prime = true;
i = 2;
while(i < count)
{
//check if count is prime
prChk = count % i;
if(!prChk)
{
prime = false;
break;
}
i++;
}
if (prime) System.out.println(count + ": prime");
else System.out.println(count + ": not prime");
count += 2; // Add to next odd number
}