sum += i;
You're adding the index; you should be adding the actual item in the ArrayList
:
sum += marks.get(i);
Also, to ensure the return value isn't truncated, force one operand to double
and change your method signature to double
:
return (double)sum / marks.size();