Sun Mar 27, 2011 8:53 pm
public double averageAge() // calculating average age in each BMI group
{
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[0]){
result=result+b;
numbers[j]++;}
}
} for (int j=0;j<3;j++)
System.out.println("Average age in group "+cat[j]+ " is "+result/this.list.length);
return result;
}
Sun Mar 27, 2011 9:07 pm
if(b==cat[0]){
result=result+b;
numbers[j]++;}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.