Can someone help me write a .addToList(); method and .getNumber(i); method or is
ID: 3677741 • Letter: C
Question
Can someone help me write a .addToList(); method and .getNumber(i); method or is the way i wrote it ok to use other.digit[i].
BigInt answer = new BigInt("0");
for(int i =0;i<other.digit.length;i++)
{
BigInt answer2 = new BigInt();
for(int k=0;k<i;k++)
{
answer2.addToList(0);
}
for(int j=0;j<this.digit.length;j++)
{
answer2.addToList(other.digit[i]*this.digit[j]);
}
answer2.multi();
answer=answer.add(answer2);
}
Explanation / Answer
public class BigInt{
private ArrayList<BigInt> bigINtlist = new ArrayList<BigInt>();
private private int[] digits;
public BigInt(String s) {
digits = new int[s.length()];
for (int i=0; i<digits.length; i++)
digits[i] = (s.charAt(digits.length-1-i)-'0');
}
public ArrayList<BigInt> addToList(BigInt obj) {
bigINtlist.add(obj);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.