Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a Java method that takes as arguments an array and another value. The method returns the position (index) of the value in the array.

Implement a Java method that takes as arguments an array and another value. The method returns the position (index) of the value in the array. For example, given an array {21, 3, 67, -8} and value 3, the routine should return 1 (since 3 occurs at position 1 in the array (what is the first index in a Java array?)). If the value is not found in the array, return -1. Your method should accept generic parameters so that arrays and values of various types can be passed in. Any single method call will pass in a value and an array of the same type. Write your method to be as flexible as possible in other ways as well; e.g. do not hard-code the length of the array that is passed in. This method does not output anything to the screen. From a separate class, call your method from main and demonstrate it working with arrays of at least three different types and sizes. Be sure to demonstrate at least one case where the value is not found in the array. The results of the method calls should be printed to the screen from here.

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

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

Students also viewed these Databases questions