hasAlternatingParity
Category: Arrays
Author: Stuart Reges
Book Chapter: 7.1
Problem: hasAlternatingParity
Write a static method called hasAlternatingParity that returns whether or not an array of integers has alternating parity (true if it does, false otherwise). The parity of an integer is 0 for even numbers and 1 for odd numbers. To have alternating parity, a list would have to alternate between even and odd numbers, as in the following list: [3, 2, 19, 8, 43, 64, 1, 0, 3] If these values are stored in an array called data and we make this call: hasAlternatingParity(data) the method would return true. If the array instead stored these values: [2, 13, 4, 1, 0, 9, 2, 7, 4, 12, 3, 2] it would return false because there are two even numbers in a row (4, 12). By definition, an empty list or a list of one element has alternating parity. You may assume the values in the array are not negative.