Valeri173

Търсене на елемент в сортиран масив

May 17th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main11 {
  4.     private static void check(int[] arr, int toCheckValue)
  5.     {
  6.         boolean test = false;
  7.         for (int element : arr) {
  8.             if (element == toCheckValue) {
  9.                 test = true;
  10.                 break;
  11.             }
  12.         }
  13.         System.out.println("Is " + toCheckValue
  14.                 + " present in the array: " + test);
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.         Scanner scan = new Scanner(System.in);
  19.         int N = scan.nextInt();
  20.  
  21.         int arr[] = new int[N];
  22.         for (int a = 0; a < N; a++) {
  23.             arr[a] = scan.nextInt();
  24.         }
  25.         int toCheckValue = scan.nextInt();
  26.         check(arr, toCheckValue);
  27.     }
  28. }
Add Comment
Please, Sign In to add comment