I would like to make a sum of 2 arrays. I don't know where is the mistake. here is the code:
public static int[] Arr(int a[], int b[]) {
System.out.println(a[] + b[]);
return a[] + b[];
}
I would like to make a sum of 2 arrays. I don't know where is the mistake. here is the code:
public static int[] Arr(int a[], int b[]) {
System.out.println(a[] + b[]);
return a[] + b[];
}
I think he wants something like this :
public static int[] Arr(int a[], int b[]) {
int[] sum = new int[a.length + b.length];
for (int i = 0; i<a.length;i++) {
sum[i] = a[i];
}
for (int i = a.length; i<a.length + b.length;i++) {
sum[i] = b[i-a.length];
}
System.out.println(Arrays.toString(sum));
return sum;
}