Overview
Pair Programming:
This exercise is reserved for pair programming in the live lab sessions.
Please skip it when doing the exercises individually.
This exercise is reserved for pair programming in the live lab sessions.
Please skip it when doing the exercises individually.
Write a program NoTriples containing a static method noTriples() with the following signature:
public static boolean noTriples(int[] nums)
Given an array of int s, we’ll say that a triple is a value appearing three times in a row in the array. The method should return true if the array does not contain any triples.
Here are some examples of evaluating the method on representative input values:
noTriples({1, 1, 2, 2, 1}) -> true noTriples({1, 1, 2, 2, 2, 1}) -> false noTriples({1, 1, 1, 2, 2, 2, 1}) -> false
Note
Hint: Check values of the array that are at indices higher than the current loop variable value. Make sure you don’t go out of bounds!
An automated test has been created for this exercise: NoTriplesTest.java.