Advertisement
lol1234561

Untitled

Apr 28th, 2023
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 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 = 0;
  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 i = 0; i<a1.length; i++ ){
  26.             if(a1[i]==find){
  27.                 total = total + 1;
  28.                 found = true;
  29.             }
  30.  
  31.         }
  32.         if (!found){
  33.             System.out.println(find + " Is not in the array.");
  34.         }
  35.         if(found == true){
  36.             System.out.println(find + " Is in the array." );
  37.         }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement