public class BigNum {
public static boolean showZero = true; // I am not sure if that is relevant
public static final int MAX_DIGITS = 40;
private int[] digits = new int [MAX_DIGITS];
public BigNum(){
for (int i=0; i < MAX_DIGITS; i++)
digits[i]=0;
}
public BigNum(int a) {
for (int i=0; i<MAX_DIGITS; i++){
int stock = (int) (a %10);
digits[i] = stock;
a = a/10;
}
}
public String show(){
String s ="";
for (int i = MAX_DIGITS-1; i>=0; i--){
if (digits[i] != 0) {
s = s + digits[i];
}
}
System.out.println("BigNum = "+s);
return s;
}
public BigNum add(BigNum t){
BigNum sum = new BigNum ();
int a = 0;
for (int i = 0; i< MAX_DIGITS; i++){
sum.digits[i] = (this.digits[i]+ t.digits[i]+a)%10;
a = (this.digits[i] + t.digits[i] + a)/10;
}
return sum;
}
public BigNum multiply(BigNum u){
BigNum e = new BigNum ();
for (int i = 0; i< 2; i++){ // the condition i<2 is wrong, but I don't know what to put in else
BigNum mult = new BigNum ();
int a = 0;
for (int k = 0; k<MAX_DIGITS; k++){
mult.digits[k] = (this.digits[i] * u.digits[k] + a)%10;
a = (this.digits[i] * u.digits[k] + a)/10;
}
e = e.somme(prod);
System.out.println("e="+e.affiche());
}
return e;
}
public static void main(String[] args) {
BigNum a = new BigNum(123);
BigNum b = new BigNum(512);
a.show();
b.show();
BigNum c = a.add(b);
c.show();
BigNum d = a.multiply(b);
d.show();
}
}