How to sum the values of each row in an array?

-1

How to sum the values of each row of an array and store the sum in an array ? Example:

3 3 3 
2 3 4
2 2 2

Results in:

9
9
6
    
asked by anonymous 20.04.2015 / 21:02

1 answer

4

I think you should start thinking about using a for loop

Example to help ...

int[][] num = new int[3][3];

for (int i = 0; i < num.length; i++) {
    int sum = 0;
    for (int j = 0; j < num[i].length; j++) {
        sum += num[j][i];
    }
    System.out.println(sum);
}
    
20.04.2015 / 21:10