Advertisement
lol1234561

Untitled

Sep 28th, 2023
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 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.             else if (x != value){
  30.                 System.out.println(value + " is not in the array.");
  31.                 break;
  32.             }
  33.         }
  34.         for (int i : num) {
  35.             if (i == value) {
  36.                 total = total + 1;
  37.             }
  38.         }
  39.         System.out.println(value + " was found a total of: " + total + " time(s)." );
  40.  
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement