coderrohan14

LoopingQues5.java

Jun 27th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt(),tmp;
  7. int min1 = Integer.MIN_VALUE,min2 = Integer.MIN_VALUE;
  8. for(int i=0;i<n;i++){
  9. tmp = sc.nextInt();
  10. if(tmp>min1){
  11. min2 = min1;
  12. min1 = tmp;
  13. }else if(tmp>min2&&tmp!=min1){
  14. min2 = tmp;
  15. }
  16. }
  17. System.out.println(min2);
  18. }
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment