My method is supposed to take two BCDs, which are ints constructed from a driver, and multiply them together:
public BCD multiplyBCDs(BCD other){ //to multiply two BCDs together
BCD basebcd = new BCD(digit);
BCD otherbasebcd = other;
int base = 0;
for(int y = 0; y<basebcd.numberOfDigits();y++){
base += digit[y];
int g = y;
while(g < basebcd.numberOfDigits()){
digit[g]*=10;
g++;
}
}
int baser = 0;
if(otherbasebcd.numberOfDigits() >= basebcd.numberOfDigits()){
for(int v = 0; v < otherbasebcd.numberOfDigits(); v++){
baser += base*otherbasebcd.nthDigit(v);
int j = v;
while(j < other.numberOfDigits()){
byten(otherbasebcd.nthDigit(j));
j++;
}
}
}
else{
for(int v = 0; v < basebcd.numberOfDigits(); v++){
baser += base*otherbasebcd.nthDigit(v);
int j = v;
while(j < other.numberOfDigits()){
byten(otherbasebcd.nthDigit(j));
j++;
}
}
}
BCD newBCD = new BCD(baser);
return newBCD;
}
the byten method is supposed to multiply "other" by 10 for each digit, resulting in a number like 838 instead of 8+3+8. But If I put in the numbers 10 and 12, the the method will add 10*1 and 10*2, which comes out to be 30 instead of 120. Any suggestions?
byten:
public int byten(int j){
j*=10;
return j;
}