Question: Consider the following method, which is supposed to return the value of the largest element in an array of integers: I / Precondition: a .

Consider the following method, which is supposed to return the value of the largest element in an array of integers:
I/ Precondition: a.length >0
public int findMax(int[] a)
1
int max=a[0];
for (int i=1;ia. length; i++)
1
if )>(max
max=a[i];
}
return max;
// Line 1
IT Line 2
// Line 3
// Line 4
// Line 5
}
Unfortunately it has two bugs. On which lines?
A. Line 1 and Line 2
B. Line 2 and Line 3
C. Line 2 and Line 4
D. Line 1 and Line 3
 Consider the following method, which is supposed to return the value

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!