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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started