0

I need help with this question. What are the three errors and their corrections? I don't really understand the code

avg is supposed to: receive any (undetermined) number of parameters of type double, compute, and return their average. Find and fix 3 errors to make this method works properly. public static double avg(double numbers) { double s; for (double v: numbers) s += v; return s/numbers.size(); }

2nd Nov 2021, 6:37 PM
Maryam Magdy
Maryam Magdy - avatar
3 Answers
+ 5
Maryam Magdy , before we are going to help you, you should put some more effort in solving the task. it looks like that this is a homework or something like this. so it's up to you now step in and start. (there is a java code in your codebits. is this code done by yourself?) happy coding!
2nd Nov 2021, 7:45 PM
Lothar
Lothar - avatar
+ 3
As the function should take multiple numbers, it should take a double array instead of a single double. The sum variable s should explicitly start off with 0
2nd Nov 2021, 9:07 PM
Lisa
Lisa - avatar