Question: Consider the following data field and method. Method maxHelper is intended to return the largest value among the first numVals values in an array; however,
Consider the following data field and method. Method maxHelper is intended to return the largest value among the first numVals values in an array; however, maxHelper does not work as intended.
private int nums;
precondition: numVals nums.length
private int maxHelperint numVals
Line : int max maxHelpernumVals ;
Line : if max numsnumVals
return max;
else
return numsnumVals ;
Which of the following corrects the method maxHelper so that it works as intended?
Responses
Insert the following statement before Line
if numVals
return numVals;
Insert the following statement before Line if numVals return numVals;
Insert the following statement before Line
if numVals
return nums;
Insert the following statement before Line if numVals return nums;
Insert the following statement between Line and Line
if numVals
return numVals;
Insert the following statement between Line and Line if numVals return numVals;
Insert the following statement between Line and Line
if numVals
return nums;
Insert the following statement between Line and Line if numVals return nums;
Insert the following statement between Line and Line
if numVals
return numVals;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
