You have this at the end of main
:
return Sum / myArr.size();
You need to move it to calculate_average
:
private static Double calculate_average( ArrayList<Double> myArr )
{
Double Sum = 0.0;
for (Double number: myArr)
{
Sum += number;
}
return Sum / myArr.size();
}
Given that main
is void
and an average makes no sense as an exit code even if it weren't, I'm assuming that is some kind of typographical error.
Some code review
- Local variables should start with a lower case letter. So
sum
, notSum
- You can use the primitive
double
instead of aDouble
object. Using the object will cause boxing/unboxing overhead. - Indent your
while
loop and its contents by four more spaces so the loop beginning aligns vertically with the code above it because it's in the same block (the method's block). - Split those last 2 braces into separate lines
- Line up the last two braces vertically with the matching opening brace
- You've started by creating your
calculate_average
method, but continue breaking upmain
. It's too long. Too much is going on there. - Change
if (count == 20)
toif (count >= 20)
. Harder to mess up, then.