Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Random rand = new Random();
  8.  
  9.         Scanner keyboard = new Scanner(System.in);
  10.  
  11.         int [] Array;
  12.  
  13.         int guess;
  14.  
  15.  
  16.         int total = 0;
  17.  
  18.         Array = new int[10];
  19.  
  20.         System.out.println();
  21.         System.out.print("Array: ");
  22.         for(int i = 0; i< Array.length; i++){
  23.             Array[i] = rand.nextInt(50);
  24.             System.out.print(Array[i] + " ");
  25.         }
  26.  
  27.         System.out.println();
  28.         System.out.println("Value to find: ");
  29.         guess = keyboard.nextInt();
  30.  
  31.  
  32.  
  33.             for (int i = 0; i < Array.length; i++) {
  34.                 if (Array[i] == guess) {
  35.                     total = total + 1;
  36.                 }
  37.             }
  38.  
  39.             System.out.println(guess + " was found " + total + " times.");
  40.  
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement