I'm supposed to add two numbers, in the form of an array
,
example
839 as an array, {9,3,8}
2039 {9,3,0,2}
The reason it is backward is because we're required to start from the one's place. I just can't figure what the size of the array should be.
public static int[] add(int [] x, int[] y){
int[] z = new int [x.length];
int j=0,
hold,
i;
for(i=0; i<=z.length-1;i++) {
z[i]=(x[i]+y[i]+j)%10;
j=(x[i]+y[i]+j)/10;
}
This is what I have currently, but the size of the array is the problem. I feel like I've tried everything but idk.