how to correct the output
i am not getting proper output format
Https://ide.codingblocks.com/s/122737
Just put a for loop for your arraylist like you put for an array to print elements. And instead of arr[i], for arraylist you have to use list.get(i) to access the ith element
still not getting right output
for (int i=0;i<list.size()-1;i++) {
System.out.print(list.get(i)+" ,");
}
You just need to make these small changes. The loop will go till i<list.size() and you have print space after the comma, not before it
for (int i=0;i<list.size();i++) {
System.out.print(list.get(i)+", ");
}
still 2 wrong outputs
You have missed one case. See if length of both arrays is same and there is a carry over in the end, then you will have to check for it and add it. For example, consider the case where input is :
5
9 9 9 9 9
5
9 9 9 9 9
Then your code will give output : 9, 9, 9, 9, 8, END
but actual output should be : 1, 9, 9, 9, 9, 8, END
So, you need to put one if condition after all the while loops have finished :
if(a>0){
list.add(a);
}