I want to print all the prime numbers between two numbers. This is my code:
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);
}
}
}
When it's run with 1 10 the output is:
2
3
5
7
11
13
17
19
23
Why doesn't it stop at 7?