Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
What should be changed in the code snippet below to fix average(double[][] values) so that it returns the average value of all the values in values?
average(double[][] values)
values
public static double average(double[][] values) { double sum = 0; int count = 0; for (double x: values) { for (double y: x) { sum += y; count++; } } return sum/count; }
Change line 4 to: for (double[] x: values) {
for (double[] x: values) {
Change line 5 to: for (double[] y: values) {
for (double[] y: values) {
Change line 6 to: sum += values[x][y]
sum += values[x][y]
Both (a) and (c)
(a), (b), and (c)