Advertisement
unknown_0711

Untitled

Sep 9th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main {
  6. public static void main (String[] args) throws java.lang.Exception {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9. int n = sc.nextInt();
  10. int arr[] = new int[n];
  11. for(int i=0;i<n;i++)arr[i]=sc.nextInt();
  12. int m=-1, ind=0;
  13. for(int i=0;i<n;i++)
  14. {
  15. if(m<arr[i])
  16. {
  17. m=arr[i];
  18. ind=i;
  19. }
  20. }
  21. m=-1;
  22. for(int i=0;i<n;i++){
  23. if(ind!=i && m<arr[i])
  24. {
  25. m=arr[i];
  26. }
  27.  
  28. }
  29. System.out.print(m);
  30.  
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement