Respuesta :

Answer:

import java.util.Random;

public class brainly {

   public static void main(String[] args) {

       int[] test_list = create_array(5);

       int target = 2; // change all of these

       int index = search(test_list, target);

       if (index == -1) {

           System.out.println("Target " + target + " not found.");

       }

       else {

           System.out.println("Target " + target + " found at index " + index);

       }

   }

   public static int[] create_array(int num) {

       Random rand = new Random();

       int[] list = new int[num];

       for (int i = 0; i < num; i++) {

           int rand_int = rand.nextInt(num); // change this to what you want

           list[i] = rand_int;

           System.out.print(rand_int);

       }

       System.out.println("\n");

       return list;

   }

 

   public static int search(int arr[], int x) {  

       int n = arr.length;  

       for(int i = 0; i < n; i++) {  

           if(arr[i] == x)  

               return i;  

       }  

       return -1;  

   }  

}

Explanation:

First off, your question is very vague, anyway, here is my interpretation.

The method create_array creates an array with the specified length.

It creates an array out of random numbers from 0 to the length.

The method search method is a simple linear search, stepping by one each cycle.

I honestly have no idea what the question is, but I added an attachment of the code.

Ver imagen reddysatvik