Advertisement
remote87

Check if an element in array is bigger than the elements on it's right and left

Nov 24th, 2020
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         int[] numArr = {24, 43, 56, 74, 49, 101, 213, 3, 89, 31, 72, 91, 99, 36, 72};
  10.         System.out.println("Number of elements in the array: " + numArr.length);
  11.         System.out.printf("Pick an element from %d to %d \n", 2, numArr.length - 2);
  12.         int checkElement = Integer.parseInt(sc.nextLine());
  13.         System.out.println(vrah(checkElement, numArr));
  14.         System.out.println(dolina(checkElement, numArr));
  15.     }
  16.  
  17.     public static boolean vrah(int element ,int...a){
  18.         return (a[element] > a[element - 1] && a[element] > a[element + 1]);
  19.     }
  20.  
  21.     public static boolean dolina(int element, int...a){
  22.         return !(vrah(element, a));
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement