Advertisement
lol1234561

Untitled

Apr 28th, 2023
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. public class Main {
  4.    public static void main(String[] args) {
  5.        Random rand = new Random();
  6.        Scanner scan = new Scanner(System.in);
  7.        int[] a1 = new int[10];
  8.  
  9.  
  10.         int min = 1;
  11.         int max = 50;
  12.         int total;
  13.  
  14.        System.out.print("Array: ");
  15.  
  16.        for(int x = 0; x< a1.length; x++){
  17.             a1[x] = rand.nextInt(max-min + 1) + min;
  18.             System.out.print(a1[x] + " ");
  19.        }
  20.        System.out.println(" ");
  21.        System.out.println("Value to find: ");
  22.        int find = scan.nextInt();
  23.  
  24.        boolean found = false;
  25.        for(int j = 0; j< a1.length; j++){
  26.            if (a1[j] == find) {
  27.                found = true;
  28.                System.out.println(find + " Is in slot: " + j);
  29.            }
  30.  
  31.        }
  32.         if (!found){
  33.             System.out.println(find + " Is not in the array.");
  34.         }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement