Advertisement
lol1234561

Untitled

Apr 27th, 2023
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 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.  
  13.        System.out.print("Array: ");
  14.  
  15. for(int x = 0; x< a1.length; x++){
  16.     a1[x] = rand.nextInt(max-min + 1) + min;
  17.  
  18.     System.out.print(a1[x] + " ");
  19.  
  20. }
  21.        System.out.println(" ");
  22.        System.out.println("Value to find: ");
  23.        int find = scan.nextInt();
  24. for(int i = 0; i<a1.length; i++ ){
  25. if(a1[i]==find){
  26.     System.out.println(find + " is in the array");
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement