1. Senior Member
Join Date
Jun 2007
Posts
114
Rep Power
0

## array 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:

2. Member
Join Date
Jun 2007
Posts
92
Rep Power
0
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.

Java 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:

3. Senior Member
Join Date
Jun 2007
Posts
114
Rep Power
0
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:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•