Free Version
Moderate

# Loop Through Cities Two-Dimensional Array of Strings

APCSA-P4TJGR

Consider the following method.

// return the number of cities from NY
public static int countNYCities(String[][] cities)
{
int count=0;
for (int r=0; r<cities.length; r++)
{
for (int c=0; c<cities[r].length; c++)
{
if (cities[r][c].indexOf ("NY")>=0)
count++;
}
}
return count;
}


Which of the following is the BEST description of this method?

A

For each column in cities, the method would loop through all the rows. The total number of loops is cities[0].length-1 multiplied by cities.length-1

B

For each row in cities, the method would loop through all the columns. The total number of loops is cities.length-1 multiplied by cities[0].length-1

C

For each column in cities, the method would loop through all the rows. The total number of loops is cities[0].length multiplied by cities.length

D

For each row in cities, the method would loop through all the columns. The total number of loops is cities.length multiplied by cities[0].length

E

This algorithm will not loop through all the row/column combinations in the cities 2-dimensional array.