Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

L A -r- P[N]

Answered: 1 week ago

Question

4. Support and enliven your speech with effective research

Answered: 1 week ago

Question

3. Choose an appropriate topic and develop it

Answered: 1 week ago