public class LargestSecondElementInArray { static int LargestElement(int arr[]){ int largest = 0; for(int i=0;iarr[largest]) { largest = i; } } return largest; } static int SecondLargest(int arr[]) { int largest = LargestElement(arr); int res = -1; for(int i = 0;iarr[res]) res = i; } } return arr[res]; } public static void main(String[] args) { int arr[] = {5,10,8,20}; System.out.println(SecondLargest(arr)); } }