We have to use an array as input and are supposed to output the second maximum element in it.
For instance if our input is a[]=10 20 30 40 50 60 70, the program should return 60. I've heard it's a very basic problem but I am new to java programming and can't figure it out.
Also, all elements are unique.
I've tried this so far and don't know how to proceed:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static int SecondLargest(int[] arr) {
int maxValue = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > maxValue) {
maxValue = arr[i];
}
}
return maxValue;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
}
}