you do not use the provided template file to answer the exam you take today, your
exam will get ZERO.
Question 1 (3 points): Review the following class and find (at least) 6 issues in the code (i.e,
coding practice, compile errors, potential logical issue, etc.) (Use question 1 template)
This program determines the second largest number in a given integer array by iterating through
its elements and updating the two largest values.
1.
class SecondLargest (
2.
3.
4.
5.
6.
public static void main(String[] args) {
int arr (10, 20, 5, 40, 30};
int secondMax FindSecond Largest (arr);
System.out.println("The second largest element is: " & secondMax);
7.
}
8.
9.
10.
11.
public static int FindSecond Largest (int[] arr) {
if (arr.length < 2) {
throw new IllegalArgumentException("The array must contain at least two elements.");
12.
}
13.
14.
int max1 Integer.MIN_VALUE;
15.
int max2
Integer.MIN_VALUE;
16.
17.
for (int num: arr) {
18.
19.
20.
21.
if (num > max1) {
max1 num;
max2 -max1;
} else if (num > max2 && num - max1) {
22.
max2 num;
23.
}
24.
}
25.
Zoom
- FUO
+ 100%
Close