Question: Write a method, called findNameIndex, which receives two parameters: 1: an array of type String, called nameArray, 2: a String called firstName and returns an
Write a method, called findNameIndex, which receives two parameters: 1: an array of type String, called nameArray, 2: a String called firstName and returns an integer value. The method searches the nameArray for the given firstName. If the firstName matches one of the values stored in the nameArray, the method returns the index of the matched name in the array. If the firstName is not found in the nameArray, the method returns -1.
Test your method by writing a Java program that its main method does the following: a) Creates a one-dimensional array, called peopleNames, of type String, and fills the array with the first names of 5 people. b) Prints the peopleNames array. c) Calls findNameIndex and passes the peopleNames array and a first name of type String to the method for the following two cases and prints the result:
i- The given first name does not exist in the peopleNames array.
ii- The given first name exists in the peopleNames array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
