You are very close. Here are the problems that prevent your code from completing correctly:
You initialize
min
andmax
too soon. Formin
this creates problems when all numbers are positive; for max, when all numbers are negative. You should declare/initialize both variables after the reading has been completed. Moving the declaration to the point after the reading loop will fix this problem.Although you correctly defined the type of
avgNum
asdouble
, the expression that you assign it remains anint
, because both its elements areint
. Therefore, the division is truncated. Change the division as follows:avgNum = (double)sum/numbers.length;
or better yet, declare sum
as double
, and remove the cast.