Write the code to calculate the average of the element included in a one-dimensional double array named rates. The array has five element.
Code
int[] avg= {
20, 13, 15, 17, 18
};
int i;
float sum=0;
for (i=0;i<avg.length;i++) {
sum=sum+avg[i];
}
println(sum/avg.length);
20, 13, 15, 17, 18
};
int i;
float sum=0;
for (i=0;i<avg.length;i++) {
sum=sum+avg[i];
}
println(sum/avg.length);
Output
16.6
Text book name : Programming and Problem solving with Java second edition
Author : Nell Dale and Chip Weems
ISBN : 978-0-7637-3402-2
ไม่มีความคิดเห็น:
แสดงความคิดเห็น