int max = 100;
String result="";
// loop through the numbers one by one
for (int i = 1; i<max; i++) {
boolean isPrimeNumber = true;
// check to see if the number is prime
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrimeNumber = false;
break; // exit the inner for loop
}
}
// print the number if prime
if (isPrimeNumber) {
result=result+i+",";//used to holding the value for i
}
lblDisplay.setText(""+result);//used to holding the value for i
}
}
最初に i の値を 1 として初期化し、システムは 1 が 100 未満かどうかをチェックします...次に進みます.... 後で j の値を 2 として初期化し、j の値が i 未満の場合、システムはループ....しかし、2 は 1 よりも大きい..なぜシステムはまだ結果を生成できるのですか? 誰でも理由を教えてもらえますか?