public class TripleUp { /******************************** * Return true if the array contains, somewhere, three increasing * adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25. * * See the verify lines below for examples of input * and expected output. * * Run this class, If you see errors, it is because the tests below * did not pass. Once the tests do pass, you will see a log of `Success!` ********************************/ public static void main(String [] args) { try { // These are the tests that will run against your code // vars = array of ints, expected answer verify(new int[]{1, 4, 5, 6, 2}, true); verify(new int[]{1, 2, 4, 5, 7, 6, 5, 6, 7, 6}, true); verify(new int[]{1, 2, 4, 5, 7, 6, 5, 7, 7, 6}, false); verify(new int[]{1, 2}, false); verify(new int[]{10, 9, 8, -100, -99, -98, 100}, true); verify(new int[]{10, 9, 8, -100, -99, 99, 100}, false); System.out.println("Success!"); } catch (Error err) { System.out.println(err.getMessage()); } } /******************************** * YOUR CODE BELOW HERE ********************************/ private static boolean triple(int[] nums) { if (nums.length >= 3){ if (nums[0] == (nums[1] - 1) && nums[0] == (nums[2] - 2)) { return true; } else if (nums.length >=4) { int[] newArray = new int[nums.length - 1]; System.arraycopy(nums, 1, newArray, 0, newArray.length); return triple(newArray); } else { return false; } } else { return false; } } /******************************** * YOUR CODE ABOVE HERE ********************************/ private static void verify(int[] nums, boolean expected) { boolean answer = triple(nums); if (answer != expected) { throw new Error("wrong answer, expected " + answer + " to equal " + expected); } } }