Mam tablicę niekwadratową. W jaki sposób mam stworzyć tablicę sumy elementów, która będzie zliczała sumę wyrazów w poszczególnych kolumnach?
Napisałem coś takiego:
public int SumaKolumny() {
int [] output = new int[tab[0].length];
for (int i = 0; i<tab[0].length; i++) {
for (int j = 0; j<tab.length; j++) {
output[j] += tab[j];
}
}
System.out.println(output);
}
Ale jest problem z tą linijką:
output[j] += tab[j];
Wyświetla:
The operator += is undefined for the argument type(s) int, int[]
Jak to naprawić?