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

Need Help on Java H/W. Thanks Here is the code for assignment

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

7 the code we have to update for this assignment import java.util.Random;

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); } } }

Task 1: Update code from Assignment 7 se only recursion to solve the problem Do not use a for loop!! Create an array that holds 1000 random integers between 1-1000 Allow the user to enter an integer to search Output the location of number if it exists in the Array. (Number could appear more than once.) or Output number does not exist in the Array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!