import java.util.TreeSet;
public class Main {
public static int findSecondLargest(int[] arr) {
if (arr.length < 2) {
throw new IllegalArgumentException("Array must contain at least two elements");
}
TreeSet<Integer> set = new TreeSet<>();
for (int num : arr) {
set.add(num);
}
set.pollLast(); // Remove the largest element
return set.last(); // The new largest element is the second largest in array
}
public static void main(String[] args) {
int[] arr = {42, 7, 93, 58, 29, 61, 17, 84, 36, 75};
System.out.println("The second largest number is: " + findSecondLargest(arr));
}
}
/*
run:
The second largest number is: 84
*/