tags:

views:

63

answers:

1
public void arrayCalculation(int[][]scores,float[]averages, int[]temp) 
{ 
    int total;
    for(int a=0; a<5; a++)
        {
            for (int b=0; b<5; b++)
                {
                  scores[a][b] =  temp[a+b*5];

                }
            }
            for(int a = 0; a <5; a++)
                {
                    total = total + scores[a];
                }
            scores[5][0] = total;

} 

i need to add up the values stored in the first row and store it in the 6th positon in the row

+2  A: 

So your problem is that scores[a] is an array of integers and not a single integer. Consequently, adding it to an integer does not make sense. I assume you meant to add the sum of scores[a][0]...scores[a][a.length-1]. So, create a method like the following:

private static int arraySum(int[] array)
{
     // Implement this yourself
     // Pseudo code:
     //     Let result = 0
     //     For each element of array (i.e. array[0] to array[array.length-1]:
     //         Add the current element to result
     //     Report the result
}

Then, instead of writing total=total+scores[a], write total+=arraySum(scores[a]).

Michael Aaron Safyan