Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions