Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To do's in the code public class ArrayLinearSearch { public static void main(String[] args) { int[] myList = {95, -10, 23, -3, 78}; System.out.print(myList: );

To do's in the code

public class ArrayLinearSearch { public static void main(String[] args) { int[] myList = {95, -10, 23, -3, 78}; System.out.print("myList: "); printArray(myList); //TODO1: Write code to search for the item 23 and print its index in the array //TODO2: Write code to search for the item 90 and print its index in the array. If the item is not in the array. // print -1 as the index } /* TODO3: * (1) * Define a method linearSearch. Given an int array and an int key, * the method searches for the key in the array and returns the * location (index) of the first occurrence of the key. * * Note tha if the key is not in the array, -1 should be returned. * * Examples: * If the list is 10, 40, 20 and 30, and the key is 20, * the method should return 2. * * If the list is 10, 40, 20 and 30, and the key is 50, * the method should return -1. * * (2) * Change the code in the main to method invocations to linearSearch. */

/* * printArray: Given an int array, the method print out all the elements of the array. */ public static void printArray(int[] list) { for (int number: list) { System.out.print(number + " "); } System.out.println(); } }

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

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago