lol1234561

Untitled

Apr 27th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 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.         for(int i = 0; i<a1.length; i++ ){
  25.             if(a1[i]==find){
  26.                 total = total + 1;
  27.             }
  28.         }
  29.  
  30.        System.out.println(find +" Was found " + total + " times");
  31.  
  32.  
  33.  
  34.  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment