public class Q3
{
public static void main(String args[]){
int i, j;
int Max = 1000;
//It's obvious that the first fifty prime numbers are less than 1000.
int counter = 1;
while (counter <= 50){
for (i = 2; i < Max; i++){
for (j = 2; j < i; j++){
if ( i % j == 0){
break;
}
}
if (j >= i){
System.out.printf("%s ", i);
counter++;
}
if(counter % 10 == 0){
System.out.print("\n");
}
}
}
}
}
This is a program that I wrote to list first 50 prime numbers, ten of them per line. However, it's not working properly because of the while loop. After execution, this program lists all prime numbers less than 1000. It seems that the while loop is not functioning at all. Can anyone tell me the reason? Many thanks.