MrDoyle

Arrays) How many Times

Jan 25th, 2021
376
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Integer [] Array = new Integer[10];
  8.         Random rand = new Random();
  9.  
  10.         System.out.println();
  11.         for (int i = 0 ; i < Array.length ; i++) {
  12.             int rand_int1 = rand.nextInt(51);
  13.             Array[i] = rand_int1;
  14.         }
  15.  
  16.         System.out.print("Array: ");
  17.         for (int i = 0 ; i < Array.length ; i++) {
  18.             System.out.print(Array[i] + " ");
  19.         }
  20.  
  21.         System.out.print("\nValue to find: ");
  22.         Scanner keyboard = new Scanner(System.in);
  23.         int numFind = keyboard.nextInt();
  24.         System.out.println();
  25.  
  26.         int Total = 0 ;
  27.  
  28.         for (int i = 0 ; i < Array.length ; i++) {
  29.             if (Array[i] == numFind) {
  30.                 Total = Total +1;
  31.             }
  32.         }
  33.  
  34.         System.out.println(numFind + " was found " + Total + " times.");
  35.  
  36.     }
  37. }
RAW Paste Data