# Sum of rows and columns in a 2d array

how do i find the sum of rows and columns in a 2d array?

• [b][red]This message was edited by RichardK at 2006-2-14 12:27:57[/red][/b][hr]
[b][red]This message was edited by RichardK at 2006-2-14 12:27:19[/red][/b][hr]
[b][red]This message was edited by RichardK at 2006-2-14 12:26:38[/red][/b][hr]
: how do i find the sum of rows and columns in a 2d array?
:
:
:
Hope this helps.

In Java there is no such concept of 2 dimensional arrays.
There are only arrays of arrays. Therefore you can't do the simple calculation rows * columns = answer.

The difference between a 2D array and an array of an array is the following. In an array of an array individual rows size can be altered. i.e. a Jagged Array.
so it is a case of get see how long each row is and add it together.

public int getCount(String[][] Array)
{
int result = 0; //temp location to store current count
for (int i = 0;i <= Array.length -1;i++){//loop around first array
//get the length of all the arrays in the first array
//and add them onto the temp variable
result += Array[i].length;
}
return result;
}