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 does the following mystery function return?
public static int mystery(int[][] values) { int count = 0; for (int row = 0; row < values.length; row++) { for (int col = 0; col < values[row].length; col++) { if (values[row][col] == 1) { count++; break; } } } return count; }
mystery returns the number of columns in which 1 appears
mystery
1
mystery returns the number of times 1 appears in values
values
mystery returns the number of times 1 appears in the first row of values
mystery returns 1 if 1 appears in the first row of values and 0 otherwise
0
mystery returns the number of rows in which 1 appears