Question: 4 . Consider the following instance variable and method. private int [ ] arr; / * * Precondition: arr.length > 0 * @return the largest
Consider the following instance variable and method. private int arr;
Precondition: arr.length
@return the largest value in array arr
public int findMax
int maxVal ;
for int val : arr
if val maxVal
maxVal val;
return maxVal;
Method findMax is intended to return the largest value in the array arr. Which of the following
best describes the conditions under which the method findMax will not work as intended?
AThe largest value in arr occurs only once and is in arrBThe largest value in arr occurs only once and is in arrarrlength C The largest value in arr is negative. D The largest value in arr is zero. E The largest value in arr occurs more than once.
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
