问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
public class DisplayPrime {
public static void main(String[] args) {
int count =0;
final int NUMBER_OF_PRIMES_PER_LINE = 8;
boolean isPrime = true;
for(int i = 2; i <= 1200; i++) {
for(int divisor = 2; divisor <= i / 2; divisor++) {
if(i % divisor == 0) {
isPrime = false;
break;
}
}
if(isPrime) {
count++;
if(count % NUMBER_OF_PRIMES_PER_LINE ==0) {
System.out.println(i);
}
else
System.out.print(i + " ");
}
}
}
}
运行结果及报错内容
输出只有2和3,没有其他质数