BigInteger没有增加?

Dan*_*ndy 1 java

由于某种原因,我的val变量在while循环中没有增加.有什么原因,为什么它没有这样做?val.add(BigInteger.ONE);

import java.math.*;

public static void main(String[] args) {

    /* Variables */
    BigInteger PQ = new BigInteger("17");
    BigInteger E = new BigInteger("7");

    BigInteger val = new BigInteger("2");

    /* Find the PRIME factors of PQ */
    while (PQ.compareTo(BigInteger.ONE) == 1) { // while the first value is greater
        if (PQ.mod(val).equals(BigInteger.ZERO)) {
            System.out.print(val + "  ");
        } else {
            val.add(BigInteger.ONE);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mit*_*eat 7

val.add(BigInteger.ONE)返回一个新值.你没有把它分配给任何东西:

val = val.add(BigInteger.ONE);
Run Code Online (Sandbox Code Playgroud)

类BigInteger