I have this code but it doesn't work!
public class Trial
{
public static void main (String [] args)
{
int average;
int m = 0;
int [] nums = {1,6,8,9,10,60,72};
average = getAverage(int [] nums);
}
public static int getAverage(int [] a)
{
int sum = 0;
for(int i=0; i<a.length; i++)
sum = sum +a[i];
int avg = sum/a.length;
return avg;
}
}
Where is the problem ? I need to get the average of that array by calling a method that calculate the average.
for (int i : a) { sum += i; }