Quote:
Originally Posted by kao2110
Again, my problem is when both "i" and "j" equal 2.
|
When both i and j equal 2, the inner loop simply doesn't execute at all. Look at its testing condition, in bold:
for (int j = 2;
j < i; ++j) {...}
So you get 2 < 2, which is false, therefore the loop doesn't even begin to execute. The logic immediately skips to this line:
if (isPrime)
which happens to be true at that time, so the program prints "i", i.e. 2.