Working in eclipse but not working here, mark the line where i made the mistake and pls do write the code for it

import java.util.*;
public class Main {
public static void main (String args[]) {
Scanner scn = new Scanner(System.in);
int n1 = scn.nextInt();
int[] a1 = new int[n1];
for (int i = 0; i < n1; i++) {
a1[i] = scn.nextInt();
}
int n2 = scn.nextInt();
int[] a2 = new int[n2];
for (int i = 0; i < n2; i++) {
a2[i] = scn.nextInt();
}
int[] sum = new int[n1 > n2 ? n1 : n2];
int i = a1.length - 1;
int j = a2.length - 1;
int k = sum.length - 1;
int c = 0;
while (k >= 0) {
int d = c;
if (i >= 0) {
d += a1[i];
}
if (j >= 0) {
d += a2[j];
}
c = d / 10;
d = d % 10;
sum[k] = d;
i–;
j–;
k–;
}
if (c != 0) {
System.out.println©;
}
for (int m = 0; m < sum.length; m++) {
System.out.println(sum[m]);
}
}

}

your output format is not right .it’s like 3, 5, 5, 9, 6, END

still not getting the right output , but getting the output on eclipse

System.out.print(", "); after the number there is comma then space
System.out.print(" ,"); not space +comma

Scanner scn = new Scanner(System.in); 		int n1 = scn.nextInt(); 		int[] a1 = new int[n1]; 		for (int i = 0; i < n1; i++) { 			a1[i] = scn.nextInt(); 		} 		int n2 = scn.nextInt(); 		int[] a2 = new int[n2]; 		for (int i = 0; i < n2; i++) { 			a2[i] = scn.nextInt(); 		} 		int[] sum = new int[n1 > n2 ? n1 : n2]; 		int i = a1.length - 1; 		int j = a2.length - 1; 		int k = sum.length - 1; 		int c = 0; 		while (k >= 0) { 			int d = c; 			if (i >= 0) { 				d += a1[i]; 			} 			if (j >= 0) { 				d += a2[j]; 			} 			c = d / 10; 			d = d % 10; 			sum[k] = d; 			i--; 			j--; 			k--; 		} 		if (c != 0) { 			System.out.println(c); 		} 		for (int m = 0; m < sum.length; m++) { 			System.out.print(sum[m]); 			System.out.print(", "); 		} 		System.out.print("End"); 	}  }

after correcting the ‘END’ thing also still not passed all test cases , only 0 and 2

for cases like
4
5 0 2 9
4
5 5 6 7,
your code was failing ,so to improve that change line 36 to
System.out.print(c+", ");
this passes all the test cases

please mark your doubt as resolved and rate as well :slight_smile: