Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Sums Arrays

Hello, I need to sum the evrey column in arrays, like exmple:

I have multidimensional arrays, like this: int[][] row ={{1, 2, 1}, {8, 1, 54}};

i need to get in the result the sum: 9, 3, 55.

I use in for loop, but i get only 9..

this is my loop:

int perTotal = 0;

     for(int i =0; i<row.length; i++){
         perTotal += row[i][0];

} System.out.println(perTotal); }

how can I get the sum of evrey column? Thank you for help :)

int perTotal=0; for(int i=0;i<row.length;i++){ perTotal += row[i][0]; } you used" row1" in conditional and "row" in body

1 Answer

sorry is a small mistake, I changed it .. but now, what can I do to get the sum someone know?