I am attempting to write a loop to iterate through a 2D array and sum each sub-array.
So far my code is as follows:
int[][] data = { { 10, 20 }, { 20, 10 }, { 50, 60 }, { 45, 20 }, { 10, 35 }, { 25, 16 } };
int[] sumOfArrays = new int[5];
for (int[] i : data) {
int sum = 0;
for (int x : i) {
sum =+ x;
}
sumOfArrays[i] = sum;
}
System.out.println(sumOfArrays);
This is not possible due to a type mismatch: (i) int[] - int
How can I resolve this?