Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following Util class, which contains two methods. The completed sum 1 D method returns the sum of all the elements of the 1

Consider the following Util class, which contains two methods. The completed sum1D method returns the sum of all the elements of the 1-dimensional array a. The incomplete sum2D method is intended to return the sum of all the elements of the 2-dimensional array m.
A 16-line code segment reads as follows. Line 1: public class Util. Line 2: open brace. Line 3: forward slash, asterisk, asterisk, Returns the sum of the elements of the 1-dimensional array a, asterisk, forward slash. Line 4: public static int sum 1D, open parenthesis, int, open square bracket, close square bracket, a, close parenthesis. Line 5: open brace, forward slash, asterisk, implementation not shown, asterisk, forward slash, close brace. Line 6: blank. Line 7: forward slash, asterisk, asterisk, Returns the sum of the elements of the 2-dimensional array m, asterisk, forward slash. Line 8: public static int sum 2D, open parenthesis, int, open square bracket, close square bracket, open square bracket, close square bracket, m, close parenthesis. Line 9: open brace. Line 10: int sum equals 0, semicolon. Line 11: blank. Line 12: forward slash, asterisk, missing code, asterisk, forward slash. Line 13: blank. Line 14: return sum, semicolon. Line 15: close brace. Line 16: close brace.
Assume that sum1D works correctly. Which of the following can replace /* missing code */ so that the sum2D method works correctly?
Three code segments. The first segment has 4 lines of code that read as follows. Line 1: for, open parenthesis, int k equals 0, semicolon, k less than m, dot, length, semicolon, k, plus, plus, close parenthesis. Line 2: open brace. Line 3: sum, plus, equals sum 1D, open parenthesis, m, open square bracket, k, close square bracket, close parenthesis, semicolon. Line 4: close brace.
The second segment has 4 lines of code that read as follows. Line 1: for, open parenthesis, int, open square bracket, close square bracket, row, colon, m, close parenthesis. Line 2: open brace. Line 3: sum , plus, equals sum 1D, open parenthesis, row, close parenthesis, semicolon. Line 4: close brace.
The third segment has 7 lines of code that read as follows. Line 1: for, open parenthesis, int, open square bracket, close square bracket, row, colon, m, close parenthesis. Line 2: open brace. Line 3: for, open parenthesis, int v, colon, row, close parenthesis. Line 4: open brace. Line 5: sum, plus, equals, v, semicolon. Line 6: close brace. Line 7: close brace.
Responses
I only
I only
II only
II only
I and II only
I and II only
II and III only
II and III only
I, II, and III

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

8. identify guidelines for building team cohesion.

Answered: 1 week ago

Question

The company has fair promotion/advancement policies.

Answered: 1 week ago