for loop - Java returning int from ArrayList<Integer> method -
i've created simple method receives arraylist<integer>
, , returns average number double
.
the code:
public static arraylist<integer> tempgsnitt(arraylist<integer> temperatur){ double sum = 0; for(int = 1; < temperatur.size(); i++) sum += temperatur.get(i); sum = sum/temperatur.size(); return sum; }
but i'm getting error method expects arraylist
return. question is; how can return double
arraylist
method?
your return type arraylist, change double.
public static double tempgsnitt(arraylist<integer> temperatur){ double sum = 0; for(int = 1; < temperatur.size(); i++) sum += temperatur.get(i); sum = sum/temperatur.size(); return sum; }
Comments
Post a Comment