我不知道BigIntegers在哪里出错了

时间:2015-07-22 05:19:33

标签: java

以下是我BigInteger的代码,我不知道哪里出错了,有人可以请更正我的代码吗?

import java.math.BigInteger;
import java.util.Scanner;

public class Class2 {

    public static void main(String[] args) {    
        Scanner num = new Scanner(System.in);
        System.out.println("Enter BigInteger number : ");
        BigInteger nbn = num.nextBigInteger();

        for(BigInteger count = BigInteger.ZERO;
                count.compareTo(nbn) <= 0;
                count.add(BigInteger.ONE)) {
            System.out.println(count);
        }
    }
}

1 个答案:

答案 0 :(得分:5)

count.add(BigInteger.ONE)的值分配回count

for (BigInteger count = BigInteger.ZERO;
        count.compareTo(nbn) <= 0;
        count = count.add(BigInteger.ONE)) {
    System.out.println(count);
}