Question: Java Program Create a class. Write a method in Java that takes as arguments an array and another value. The method returns the position (index)
Java Program
Create a class. Write a method in Java 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 {2, 4, 6, 8} and value 6, the routine should return 2 (since 6 occurs at position 2 in the array (what is the first index in a Java array?)).
Your method should use generic parameters so that arrays and values of various types can be passed in, although any single method call will pass in an array and a value 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. The results of the method calls should be printed to the screen from here in main.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
