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");
}
}
}
}
}
これは、最初の 50 個の素数を 1 行に 10 個リストするために私が書いたプログラムです。ただし、while ループのため、正しく動作していません。実行後、このプログラムは 1000 未満のすべての素数をリストします。while ループがまったく機能していないようです。誰でも理由を教えてもらえますか?どうもありがとう。