Advertisement
lol1234561

Untitled

Sep 28th, 2023
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 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.         System.out.print("Array 1: ");
  11.  
  12.         for( int x = 0; x < num.length; x++){
  13.             num[x] = rand.nextInt(100)+1;
  14.             System.out.print( num[x] + " ");
  15.  
  16.         }
  17.         System.out.print("\nValue to find: ");
  18.         int value = scan.nextInt();
  19.  
  20.        
  21.  
  22.         for (int x: num){
  23.             if( x == value){
  24.                 System.out.println(value + " is in the array.");
  25.             }
  26.  
  27.         }
  28.  
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement