Question: Consider the following method which accesses the properly declared and initialized int array arr and is intended to return the maximum value in arr.

Consider the following method which accesses the properly declared and initialized int

 

Consider the following method which accesses the properly declared and initialized int array arr and is intended to return the maximum value in arr. public int findMax() { int maxVal = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > maxVal) } { maxVal = arr[i]; } return maxVal; In which of the following situations, if any, does findMax() not work as intended? If the largest value in arr is negative b. If the largest value in arr is zero c. If the largest value in arr occurs only once and is at arr[0] d. If the largest value in arr occurs only once and is at arr[arr.length - 1] e. None; findMax() works as intended for all int arrays

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 Databases Questions!