Question: Write the following method: public static int indexOfFirstPair(int [] myArray) The method receives a single parameter, an integer array myArray. The method is to find

Write the following method:

public static int indexOfFirstPair(int [] myArray)

The method receives a single parameter, an integer array myArray. The method is to find the location of the first pair of adjacent matching values in the array. Once found, the method is to return the index of the first value of this pair. Note: this must be exactly a pair it cannot be part of three or more values in a row. If there is no such index, the method is to return the value 1 (negative 1).

In the following example, the value 88 appears as three in a row, so it is not an exact pair. The value 77 appears as four in a row, so again, it is not a pair. The values 44 and 99 have exactly two consecutive values in a row. The two 44 values come before the 99 pair, so the return value is the index of the first 44, which is 10.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
88 88 88 63 29 77 77 77 77 50 44 44 8 0 99 99

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!