Question: Need Help on Java H/W. Thanks Here is the code for assignment 7 the code we have to update for this assignment import java.util.Random; import
Need Help on Java H/W. Thanks

Here is the code for assignment 7 the code we have to update for this assignment

import java.util.Random; import java.util.Scanner;
public class RandomArray { public static int search(int ar[], int key){
for(int i=0; i if(ar[i] == key) return i; return -1; } public static void main(String[] args) { int arr[] = new int[1000]; Scanner sc = new Scanner(System.in); Random random = new Random(); for(int i=0; i arr[i] = random.nextInt(100)+1; } System.out.print("Enter integer to be search: "); int key = sc.nextInt(); int index = search(arr, key); if(index == -1){ System.out.println(key+" is not available in array"); }else{ System.out.println(key+" is available at location "+index); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
