Advertisement
Blonk

Untitled

Feb 21st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2. import java.util.*;
  3. import java.util.concurrent.ThreadLocalRandom;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Random rand = new Random();
  11.  
  12.         int[] myList;
  13.         myList = new int[10];
  14.  
  15.         System.out.print("Array: ");
  16.         for (int i = 0; i < myList.length; i++) {
  17.             myList[i] = 1 + rand.nextInt(50);
  18.             System.out.print(myList[i] + " ");
  19.         }
  20.  
  21.         Scanner keyboard = new Scanner(System.in);
  22.  
  23.  
  24.         System.out.println();
  25.         System.out.println("\nValue to find: ");
  26.         int arrayChosen = keyboard.nextInt();
  27.  
  28.         for (int i = 0; i < myList.length; i++ ) {
  29.             if (myList[i] == arrayChosen){
  30.                 System.out.println(arrayChosen + " is in the array");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement