如何用int阵列表示50位整数



指南要求以下内容:

BigIntegers will be represented with 50 digit arrays of int (where each integer in the array is an integer in the range 0..9).
You will have a class called BigInteger that has the following methods:
BigInteger( ) --- initialize the BigInteger to 0
BigInteger(int n) --- initialize the BigInteger to the value of n
BigInteger( BigInteger n) --- a copy constructor

我的问题是,最有效的方法是什么?目前,我有:

public class BigInteger {
    int[] BigInteger = new int[50];
    public BigInteger() {
        for(int i = 0; i < BigInteger.length; i++) {
            BigInteger[i] = 0;
        }
    }

似乎有效,但仅用于将数组初始化为0 ....我已经检查了堆栈溢出,但是空无一人。有人可以将我指向如何解决这个问题吗?

我不是Java的家伙,但是那是什么。

public BigInteger() {
    for(int i = 0; i < BigInteger.length; i++) {
        BigInteger[i] = 0;
    }
}
public BigInteger(BigInteger bigInteger) {
    for(int i = 0; i < BigInteger.length; i++) {
        BigInteger[i] = bigInteger[i];
    }
}
public BigInteger(int n) {
    String nstr = n.toString(); // not sure
    int pos = 49;
    for(int i = nstr.length - 1; i >= 0 ; i--) {
        BigInteger[pos] = Integer.parse(nstr [i]); // parse each char, you get the idea
        pos--;
    }
}

对@andreas的编辑。

最新更新