1. Member
Join Date
Nov 2014
Posts
3
Rep Power
0

How can I find the overall averages of the columns in this array?
when i run my code it gives me an output that looks like this (showing me wrong averages):

0 1 2 3 overall grade
Emu,Emma 35 81 75 40 72.83333333333334
Aardvark,Alice 42 85 22 0 65.11111111111111
Dodo,Donald exc 12 25 0 54.17391304347826
Cassowary,Cassie 50 97 72 68 62.758620689655174

my code is :

Java Code:
``` public static double[] computeAllGrades(int[][] scoreTable, int[] itemPointValues)
{

{
double totalPoints = 0;
double totalPointsPossible = 0;

int k = 0;

for(int j = 0 ; j < scoreTable.length ; j++)
{
for(int i = 0 ; i < scoreTable[0].length ; i++)
{
if(scoreTable[j][i] == -1)
{
totalPoints = totalPoints + 0;
totalPointsPossible = totalPointsPossible + 0;

}
else
{
totalPoints = totalPoints + scoreTable[j][i];
totalPointsPossible = totalPointsPossible + itemPointValues[i];
}

}

k++;
}

Last edited by shadow240; 11-06-2014 at 12:26 AM. Reason: formatting

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

First, please place your code between code tags [code][/code] to preserve formatting. You need to sprinkle some print
statements in your code to make certain you are averaging the correct values.

Regards,
Jim

3. Member
Join Date
Nov 2014
Posts
3
Rep Power
0

i am not sure what to do next

Try debugging the code to see what it is doing that is unexpected.

Add some println() statements as Jim suggested to show the value of variables as their value is changed. The print out will show you what the computer sees when it executes the code.
Last edited by Norm; 11-06-2014 at 02:40 AM.

Line #28 inside that doubly nested loop is very suspicious ...

kind regards,

Jos

#### Posting Permissions

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