Question: Consider the following method, which is intended to return the number of columns in the two - dimensional array arr for which the sum of

Consider the following method, which is intended to return the number of columns in the two-dimensional array arr for which the sum of the elements in the column is greater than the parameter val.
public int countCols(int[][] arr, int val)
{
int count =0;
for (int col =0; col < arr[0].length; col++)// Line 5
{
int sum =0;
for (int[] row : col)// Line 8
{
sum += row[col]; // Line 10
}
if (sum > val)
{
count++;
}
}
return count;
}
The countCols method does not work as intended. Which of the following changes should be made so the method works as intended?
Responses
Line
should be changed to for (int col =0; col < arr.length; col++)
Line 5 should be changed to for (int col =0; col < arr.length; col++)
Line
should be changed to for (int row : col)
Line 8 should be changed to for (int row : col)
Line
should be changed to for (int[] row : arr)
Line 8 should be changed to for (int[] row : arr)
Line
should be changed to sum += arr[col];
Line 10 should be changed to sum += arr[col];
Line
should be changed to sum += arr[row][col];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!