WAP to find the second highest number in an array

import java.util.*; class CT2 { public static void main(String[] args) { int i; int [] arr = new int [10]; Scanner sc = new Scanner(System.in); System.out.println("Enter 10 Numbers : "); for(i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); System.out.println("Here is the second highest number of array : " + arr[arr.length-2]); } } Copy Code
Expected Output:
Enter 10 Numbers:
3
1
4
5
9
2
8
7
6
10
Here is the second highest number of array: 9