Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Random rand = new Random();
- Scanner keyboard = new Scanner(System.in);
- int [] Array;
- int guess;
- int total = 0;
- Array = new int[10];
- System.out.println();
- System.out.print("Array: ");
- for(int i = 0; i< Array.length; i++){
- Array[i] = rand.nextInt(50);
- System.out.print(Array[i] + " ");
- }
- System.out.println();
- System.out.println("Value to find: ");
- guess = keyboard.nextInt();
- for (int i = 0; i < Array.length; i++) {
- if (Array[i] == guess) {
- total = total + 1;
- }
- }
- System.out.println(guess + " was found " + total + " times.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement