Here is my dilemma...
I am in my first programming course, and I am supposed to be developing a random prime number generator. Unfortunately I have hit a snag and need some assistance. Can anyone help me? My source code is below, my issue is when I run my set of numbers (2-20) only 2 is registered as prime and the rest go as not prime. Any suggestions?
import java.util.*;
public class PNG
{
public static void main(String[] args)
{
int num1, num2, count, i = 2, prChk = 0 , m = 0;
Scanner keyIn = new Scanner (System.in);
System.out.print("Enter First number : ");
num1 = keyIn.nextInt();
System.out.print("Enter Second number : ");
num2 = keyIn.nextInt();
count = num1;
while(count <= num2)
{
while(i < count)
{
prChk = count % i;
if(prChk == 0)
m = 0;
else if(prChk == 1)
m = 1;
i++;
}
if (m == 0)
System.out.println(count + ": prime");
else if(m ==1)
System.out.println(count + ": not prime");
count++;
}
}
}
Thanks again!
James Campbell