The following method, which is intended to find the maximum element of the parameter array, is incorrect. public int max (int[]
- A.{ int max = 0; for (int i=0; i<a.length; i++) { if(a[i]>max) { max = a[i]; } } return max; } (a) It fails whenever the array contains a 0.
- B.It fails whenever the array contains a negative number.
- C.It fails whenever the array contains only negative numbers.
- D.It fails whenever the first element of the array a is the largest.
Show answer
Answer: C. It fails whenever the array contains only negative numbers.
If all elements are negative, the condition a[i]>0 is never met, returning incorrect max 0.