Question: 4 . Consider the following instance variable and method. private int [ ] arr; / * * Precondition: arr.length > 0 * @return the largest

4. Consider the following instance variable and method. private int[] arr;
/** Precondition: arr.length >0
* @return the largest value in array arr */
public int findMax()
{
int maxVal =0;
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?
(A)The largest value in arr occurs only once and is in arr[0].(B)The largest value in arr occurs only once and is in arr[arr.length -1].(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 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 Programming Questions!