Advertisement
CR7CR7

IndexFirstElement

Jun 25th, 2022
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class Neighbour {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int size = Integer.parseInt(scanner.nextLine());
  10.         String[] input = scanner.nextLine().split(" ");
  11.         List<Integer> result = new ArrayList<>();
  12.         for(int i = 0; i < size;i++){
  13.             result.add(Integer.parseInt(input[i]));
  14.         }
  15.           int index = -1;
  16.         for(int i = 1; i < result.size() -1 ;i++){
  17.             if( result.get(i - 1) < result.get(i) && result.get(i) > result.get(i + 1)){
  18.                 index = i;
  19.                 break;
  20.             }/*else{
  21.                  index = result.indexOf(result.get(i + 1));
  22.                 break;
  23.             }*/
  24.         }
  25.         System.out.println(index);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement