Advertisement
lol1234561

Untitled

Sep 28th, 2023
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Random rand =  new Random();
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         int[] num = new int[10];
  9.  
  10.         int total = 0;
  11.  
  12.         System.out.print("Array 1: ");
  13.  
  14.         for( int x = 0; x < num.length; x++){
  15.             num[x] = rand.nextInt(100)+1;
  16.             System.out.print( num[x] + " ");
  17.  
  18.         }
  19.         System.out.print("\nValue to find: ");
  20.         int value = scan.nextInt();
  21.  
  22.  
  23.  
  24.         for (int x: num){
  25.             if( x == value){
  26.                 System.out.println(value + " is in the array.");
  27.  
  28.             }
  29.         }
  30.         for(int x = 0; x < num.length; x++){
  31.             if(num[x] ==  value){
  32.                 total = total +1;
  33.             }
  34.         }
  35.         System.out.println(value + " was found a total of: " + total + " time(s)." );
  36.  
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement