Kotlinlearncs.online LogoJava
Return to List

Homework: Array All Pairs

Created By: learncs.online Staff
/ Version: 2022.1.0

Write a method arrayAllPairs that returns whether a passed int[] array is composed entirely of adjacent pairs of the same value. For example, the array {1, 1, 2, 2} and the array {4, 4, -1, -1} are composed of adjacent pairs of the same element, but {2, 1, 1, 2} and {4, 4, -1, 0} are not. To be composed entirely of pairs of the same element, the array must contain an even number of elements. If the passed array is empty, you should return false.

You will need to construct your loop carefully to complete this problem! We suggest that you examine the array looking for a counterexample: meaning a pair of adjacent elements that do not have the same value.