Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Java beginner needing help with Random Prime Number Generator.
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?
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;
if (m == 0)
System.out.println(count + ": prime");
else if(m ==1)
System.out.println(count + ": not prime");