我正在設計一個名爲HugeInteger的類 - 它使用40個數字數組來存儲整數。我提供了一個名爲parse的方法,它在其中接收一個字符串,提取每個數字,如下面的代碼片段所示。我也提供方法添加它接收一個類HugeInteger的對象做添加。 爲添加提供的方法沒有按照建議工作,如果您可以幫助我解決問題,我希望您。 P.S我注意到了一些類似的問題,但它沒有幫助我。設計巨大的整數類
private int [] integerDigits = new int[SIZE];
//constructor that enables an object of class to be initialised when it is declared
public HugeInteger(String stringOfIntegers)
{
setOfIntegers = stringOfIntegers;
}//end of constructor
private int[] parseFunction (String str)
{
for (int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if (Character.isDigit(ch))
integerDigits[i] = Character.getNumericValue(ch);
else
integerDigits[i] = 0;
}
return integerDigits;
}//end of method parseFunction
public HugeInteger addFunction(HugeInteger number)
{
parseFunction(setOfIntegers);
return new HugeInteger(setOfIntegers +number.parseFunction(setOfIntegers));
}//end of method addFunction
'規定的添加方法是不工作的proposed' ...怎麼樣? – talnicolas 2012-03-27 18:04:15
這是家庭作業,還是有其他一些你不喜歡'BigInteger'的原因? – 2012-03-27 18:04:36
@Louise,這是一項功課,因爲我目前正在自學Java。 – Sinan 2012-03-27 18:05:46