The following method, which is intended to find the maximum element of the parameter array, is incorrect. When does it fail? public int max (int[]…
The following method, which is intended to find the maximum element of the parameter array, is incorrect. When does it fail?
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;
}From the Combined Bank Officer (IT) October 2024 – Preliminary (BIBM) exam, question 90 of 95.