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
Which of the following prints the number of times the string “karel” appears in the 2D array String[][] petNames?
String[][] petNames
int count = 0; for (int row = 0; row < petNames[col].length; row++) { for (int col = 0; col < petNames.length; col++) { if (petNames[row][col].equals("karel")) { count++; } } } System.out.println(count);
int count = 0; for (int row = 0; row < petNames.length; row++) { for (int col = 0; col < petNames[row].length; col++) { if (petNames[col][row].equals("karel")) { count++; } } } System.out.println(count);
int count = 0; for (int row = 0; row < petNames.length; row++) { for (int col = 0; col < petNames[row].length; col++) { if (petNames[row][col].equals("karel")) { count++; } } } System.out.println(count);
int count = 0; for (int col = 0; col < petNames.length; col++) { for (int row = 0; row < petNames[col].length; row++) { if (petNames[row][col].equals("karel")) { count++; } } } System.out.println(count);
int count = 0; for (int row = 0; row < petNames[col].length; col++) { for (int col = 0; col < petNames[row].length; col++) { if (petNames[row][col].equals("karel")) { count++; } } } System.out.println(count);