Hi, basically i have a2D array 6x8which holds integers i need to get a total for each row - can anyone help please??!!!?

Thank you

Albert:rolleyes:

Printable View

- 07-01-2007, 02:04 AMAlbertarray problem
Hi, basically i have a

**2D array 6x8**which holds integers i need to get a total for each row - can anyone help please??!!!?

Thank you

**Albert**:rolleyes: - 07-01-2007, 02:08 AMMarcus
A total of what for which row? I'm assuming you want to add up all of the integers in the first row...then the total of all the integers in the second, etc.

First how would you do this on paper? Write out your algorithm and then try and translate it into java.

For a hint, here is some code that will print everything in your 2d array.

Code:`//assume foo is an int [][] array initilized earlier.`

for(int i=0;i<array.length;i++)

{

System.out.println("Printing the data in row "+i);

for(int j=0;j<array[i].length;j++)

{

System.out.println("Value at array["+i+"]["+j+"] is "+array[i][j]);

}

System.out.println("moving to next row");

}

**Marcus**:cool: - 07-01-2007, 02:13 AMAlbert
This is what i want to do, in pseudo code:

for each row i in the 2d array // that is for each student

set the total for the ith student to be 0

for each column j in the row // that is for each mark for the ith student

add the mark stored at row i column j to the total for the ith student // something like total += marks[i][j]

end for // where marks is the 2d array

output the total for the ith student

calculate and output the grade for the ith student

end for

I just cant put it in java.

Thanks.

**Albert**:rolleyes: