如果让BigInteger取余 就是mod
然后如何在BigInteger中使用for循环呢?
试了一下,
好像不行

解决方案 »

  1.   

    还有怎么从int转成BigInteger呢
    谢了
      

  2.   

    BigInteger.intValue();返回一个int值。Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations. 
      

  3.   

    BigInteger(String val)传入一个String,这个String是数字。比如BigInteger("1");
      

  4.   

    BigInteger interger= new BigInteger(1);
    在对象里使用for循环?没理解
      

  5.   

    BigInteger(String val) 将 BigInteger 的十进制字符串表示形式转换为 BigInteger。
    BigInteger他是一个类,不是基本数据类型。
      

  6.   


    package 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 + " ");
    }
    }
    }