我想打印两个数字之间的所有素数。这是我的代码:
package sphere;
import java.math.BigInteger;
import java.io.*;
class PrimeTest2 {
public static void main(String args[]) throws java.lang.Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s = r.readLine();
String [] splitted = s.split(" ");
BigInteger lower = new BigInteger(splitted[0]);
BigInteger upper = new BigInteger(splitted[1]);
int lowerAsInt = Integer.parseInt(splitted[0]);
int upperAsInt = Integer.parseInt(splitted[1]);
BigInteger intermediate = lower;
for (int i=lowerAsInt; i<upperAsInt; i++) {
intermediate = intermediate.nextProbablePrime();
System.out.println(intermediate);
}
}
}
当它以 1 10 运行时,输出为:
2
3
5
7
11
13
17
19
23
为什么不停在7点?