Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner keyboard = new Scanner(System.in);
  8.         int[] numbers = new int[10];
  9.         Random dom = new Random();
  10.  
  11.         System.out.println("Array 1: ");
  12.         for (int h = 0; h < numbers.length; h++) {
  13.             int rand_int = dom.nextInt(50);
  14.             numbers[h] = rand_int;
  15.             System.out.print(numbers[h] + " ");
  16.  
  17.         }
  18.         System.out.println();
  19.         System.out.println("Value to find: ");
  20.         int value = keyboard.nextInt();
  21.  
  22.         int total = 0;
  23.         for (int h = 0; h < numbers.length; h++) {
  24.             if (value == numbers[h])
  25.                 System.out.println(value + " is in slot " + (h));
  26.             total++;
  27.         }
  28.  
  29.         if (total == 0) {
  30.             System.out.println(value + " is not in the array.");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement