Advertisement
Hey_Donny

First Largest Than Neighbors

Mar 17th, 2022
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class FirstLargerThanNeighbors {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int N = Integer.parseInt(scanner.nextLine());
  8. String[] input;
  9. input = scanner.nextLine().split(" ");
  10. int[] array = new int[input.length];
  11. for (int i = 0; i < N; i++) {
  12. array[i] = Integer.parseInt(input[i]);
  13. }
  14.  
  15. int counter;
  16. for (int i = 1; i <= array.length - 1; i++) {
  17. if (array[i] > array[i - 1] && array[i] > array[i + 1]) {
  18. counter = i;
  19. System.out.println(counter);
  20. break;
  21. }
  22. }
  23. }
  24. }
Advertisement
RAW Paste Data Copied
Advertisement