java - Why can I not convert my integer to a double? -


i trying work out average of array cannot convert int double? why happening?

private void avgofarray(){              mywindow.clearout();             int total = 0;             int[] = new int[4];             int = 0;             double avg = 0.0;             while (i < a.length) {                 a[i] = 1 + (int) (math.random() * 10);                 mywindow.writeoutline(a[i]);                 total += a[i];                 i++;             }             avg = (double) i;             mywindow.writeoutline(total/double.parsedouble(i));           } 

the correct way calculate average like,

double avg = total / (double) i; mywindow.writeoutline(avg); 

boxing int double doesn't make sense, try , parse it.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -