17.1. Parsons Problems for Experiments

Try to solve each of the following. Click the Check Me button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block or two that aren’t needed in the correct solution. Try to solve these on your phone or other mobile device!

Create the function boolean has22(int[] arr) that takes an array of ints, arr, and returns true if there are at least two items in the array arr that are adjacent and both equal to 2. For example, has22({1, 2, 2}) returns true and has22({1, 2, 1, 2}) returns false.

Create the function has22(int[] arr) that takes an array of ints, arr and returns true if there are at least two items in the array arr that are adjacent and both equal to 2. For example, has22({1, 2, 2}) returns true and has22({1, 2, 1, 2}) returns false.

Write the function has22(int[] arr) that takes an array of ints, arr and returns true if there are at least two items in the array arr that are adjacent and both equal to 2. For example, has22({1, 2, 2}) returns true and has22({1, 2, 1, 2}) returns false.

Create the function has3OddOrEven(int[] arr) that takes an array of ints, arr and returns true if the array contains either 3 odd or even values that are adjacent. For example has3OddOrEven({2, 1, 3, 5}) returns true and has3OddOrEven({2, 1, 2, 5}) returns false.

Create the function has3OddOrEven(int[] arr) that takes an array of ints, arr and returns true if the array contains either 3 odd or even values that are adjacent. For example has3OddOrEven({2, 1, 3, 5}) returns true and has3OddOrEven({2, 1, 2, 5}) returns false.

Write the function has3OddOrEven(int[] arr) that takes an array of ints, arr and returns true if the array contains either 3 even or 3 odd values all next to each other. For example has3OddOrEven({2, 1, 3, 5}) returns true and has3OddOrEven({2, 1, 2, 5}) returns false.

Create the function isAscending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in ascending order. For example, isAscending({1, 2, 3}) returns true and isAscending({1, 2, 3, 2}) returns false.

Create the function isAscending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in ascending order. For example, isAscending({1, 2, 3}) returns true and isAscending({1, 2, 3, 2}) returns false.

Write the function isAscending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in ascending order. For example, isAscending({1, 2, 3}) returns true and isAscending({1, 2, 3, 2}) returns false.

Create the function isDescending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in descending order. For example, isDescending({3, 2, 1}) returns true and isDescending({3, 2, 1, 2}) returns false.

Create the function isDescending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in descending order. For example, isDescending({3, 2, 1}) returns true and isDescending({3, 2, 1, 2}) returns false.

Write the function isDescending(int[] arr) that takes an array of ints, arr and returns true if the all of the elements in the array are in descending order. For example, isDescending({3, 2, 1}) returns true and isDescending({3, 2, 1, 2}) returns false.

Create the function isLevel(int[] arr, int x) that takes an array of ints, arr and returns false if the difference between any two adjacent values is greater than the passed value, x. For example, isLevel({3, 4, 6}, 2) returns true and isLevel({3, 5, 8, 6}, 2) returns false.

Create the function isLevel(int[] arr, int x) that takes an array of ints, arr and returns false if the difference between any two adjacent values is greater than the passed value, x. For example, isLevel({3, 4, 6}, 2) returns true and isLevel({3, 5, 8, 6}, 2) returns false.

Write the function isLevel(int[] arr, int x) that takes an array of ints, arr and returns false if the difference between any two adjacent values is greater than a passed value, x. For example, isLevel({3, 4, 6}, 2) returns true and isLevel({3, 5, 8, 6}, 2) returns false.

You have attempted of activities on this page