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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started