Advertisement
lol1234561

Untitled

Sep 29th, 2023
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 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.         boolean found = false;
  12.         int top = num[0];
  13.  
  14.         System.out.print("Array 1: ");
  15.  
  16.         for( int x = 0; x < num.length; x++){
  17.             num[x] = rand.nextInt(100)+1;
  18.             System.out.print( num[x] + " ");
  19.  
  20.         }
  21.         System.out.print("\nValue to find: ");
  22.         int value = scan.nextInt();
  23.  
  24.  
  25.  
  26.         for (int x: num){
  27.             if( x == value){
  28.                 total = total + 1;
  29.                 found = true;
  30.             }
  31.         }
  32.         if(found){
  33.             System.out.println(value + " is in the array.");
  34.         }
  35.         if(!found){
  36.             System.out.println(value + " is not in the array.");
  37.         }
  38.  
  39.         System.out.println(value + " was found a total of: " + total + " time(s)." );
  40.  
  41.         for (int i : num) {
  42.             if (i > top) {
  43.                 top = i;
  44.             }
  45.         }
  46.         System.out.println("The largest number is: " + top);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement