Calculating average of an array

Have written a program for my uni assignment that stores information about fitness club members(such as name, age weight, BMI index etc.) One of the operations that program must perform is to calculate an average BMI index. The method I have written returns value of 0 and can't figure out where the problem lays.

Code Java:

public double averageBmi()//to calculate average BMI index
{
double numbers[]=new double[this.list.length];
double result=0;
for(int i=0;i<numbers.length;i++){
double b=this.list[i].Bmiindex;
result=result+numbers[i];
}
System.out.println("Average BMI is "+result/numbers.length);
return result;
}

Any ideas why?

Re: Calculating average of an array

numbers is empty !!! wath is double b ?

Re: Calculating average of an array

double b is accessing list of all Bmiindexes stored in another class

Re: Calculating average of an array

but number[] is still empty 0+0=0

meybe rezult=rezult+b

Re: Calculating average of an array

It works now! Thanks a lot!

Re: Calculating average of an array

Facing the same issue with the method calculating average age for each group:(

Code Java:

public double averageAge() //
{
double numbers[]=new double[this.list.length];
double result=0;
char[] cat={'O','U','N'};
for (int i=0;i<this.list.length;i++){
int b=this.list[i].age;
for(int j=0;j<3;j++){//loop runs three times, as there are three categories
if(b == cat[j])
result=result+b;
}
} for (int j=0;j<3;j++)
System.out.println("Average age in group "+cat[j]+ " is "+result/numbers.length);
return result;
}

Re: Calculating average of an array

I have removed your other thread as the content is duplicated.

Re: Calculating average of an array

1. Most probably, your list is throwing garbage instead of any value.

2. You should use explicit type casting in calculation.