- #1
apiwowar
- 96
- 0
Thers a class called BigInt and it has a size and digit. size is the number of digits in the integer that is entered and digit is an array that holds the integer.
Theres a method in the class called plus which is supposed to add two BigInts together. If there is a remainder the remainder is supposed to carry over like in regular addition.
This is how the numbers are passed from the main class to the BigInt Class.
num2 = num.plus(num1);
Below is the method that I am working on right now to add the two BigInts.
public BigInt plus(BigInt arg) { // add two BigIntís
BigInt number = arg;
BigInt sum = new BigInt();
sum.digit = new int[50];
int remainder = 0;
for(int i = 0; i <= size; i++)
sum.digit = this.digit + number.digit + remainder;
return sum;
}
I'm not even sure if i passed in the number correctly. or if i made the sum array correctly.
I know that the for loop is going to be used to add the two BigInts but I am not sure where they start or where they end because I am not sure about what I am passing into this method.
Was i right when i said this.digit?
I know there has to be a mod in an if statement that gives remainder a new value if the sum is greater than 9. I just wanted to get this rough method to print something out before i went any further.
any help would be appreciated. If needed, i can add the entire main class and BigInt Class for clarity.
Theres a method in the class called plus which is supposed to add two BigInts together. If there is a remainder the remainder is supposed to carry over like in regular addition.
This is how the numbers are passed from the main class to the BigInt Class.
num2 = num.plus(num1);
Below is the method that I am working on right now to add the two BigInts.
public BigInt plus(BigInt arg) { // add two BigIntís
BigInt number = arg;
BigInt sum = new BigInt();
sum.digit = new int[50];
int remainder = 0;
for(int i = 0; i <= size; i++)
sum.digit = this.digit + number.digit + remainder;
return sum;
}
I'm not even sure if i passed in the number correctly. or if i made the sum array correctly.
I know that the for loop is going to be used to add the two BigInts but I am not sure where they start or where they end because I am not sure about what I am passing into this method.
Was i right when i said this.digit?
I know there has to be a mod in an if statement that gives remainder a new value if the sum is greater than 9. I just wanted to get this rough method to print something out before i went any further.
any help would be appreciated. If needed, i can add the entire main class and BigInt Class for clarity.