java - BigInteger 不增加?

标签 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);
        }
    }
}

最佳答案

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

val = val.add(BigInteger.ONE);

Class BigInteger

关于java - BigInteger 不增加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39432779/

相关文章:

java - 如何在 javafx 2.4.0 中转换停止后触发事件?

java - 吉斯。注入(inject)静态方法

java - Hibernate ObjectNotFoundException 不一致

java - 如何从服务器获取序列化策略文件的强哈希名称?

java - 在 Java 中使用另一个类的私有(private)方法

java - Struts2 portlet NotSerialized 异常

java - 如何在 Java 中使用 System.out.println 在控制台中打印突出显示的彩色文本

java - 从字符串数组中(快速)获取字符串

java - 如何处理大字符串和有限的内存

java - 如何在 Kotlin 中声明原始类型?