Java codepackage csdn;
import java.math.BigInteger;
public class IntegerTest {
public static void main(String[] args) {
int a = 10;
BigInteger b = BigInteger.valueOf(a); // int -> BigInteger
System.out.println(b);
BigInteger c = BigInteger.valueOf(100);
// 1 - 100 中的质数 有的麻烦 ... 仅供参考 BigInteger是可以用for循环的
for (BigInteger i = BigInteger.valueOf(2); i.compareTo(c) < 0; i = i.add(BigInteger.valueOf(1))) {
boolean flag = true;
for (BigInteger j = BigInteger.valueOf(2); j.compareTo(BigInteger.valueOf(Long.parseLong((int)Math.sqrt(Double.parseDouble(i+""))+""))) <= 0; j = j.add(BigInteger.valueOf(1))) {
if (i.mod(j) == BigInteger.ZERO) {
flag = false;
}
}
if (flag)
System.out.print(i + " ");
}
}
}