java - Averaging the values in while loop -
this question has answer here:
so have public accessor method called gettseconds , have called in while loop below 20 times:
int =0; double sum = 0; double average =0; while (i < 20) { call.read(); sum = sum + call.getseconds(); system.out.println(sum); average = sum / 10.0; }
so called read 20 times , calculate how long took read file each time , average total time.but keep getting last time average instead of actual average.
i enticed change more - lets keep as possible of original - want this?
double sum = 0; double average =0; (int i=0; < 20; i++) { call.read(); sum = sum + call.getseconds(); } average = sum / 20.0; system.out.println(average);
note original while (i < 20)
- condition true, in effect run forever. maybe had different intentions - in case, please more clear.
Comments
Post a Comment