Question: Consider the following code segment. public static int findMaxValue ( int [ ] [ ] arr ) { int max = 0 ; for (

Consider the following code segment.
public static int findMaxValue(int[][] arr){
int max =0;
for (int i =0; i < arr.length; i++){
for (int j =0; j < arr[0].length; j++){
if (arr[i][j]> max){
max = arr[i][j];
}
}
}
return max;
}
Which of the following options identifies the error in the given code segment?
A. The initial value of max should be set to Integer.MIN_VALUE instead of 0.
B. The loop condition for the outer loop should be i < arr.length -1.
C. The loop condition for the inner loop should be j < arr.length -1.
D. The condition arr[i][j]> max should be arr[i][j]< max.
E. The return type of the method should be void instead of int.

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!