Question: Problem #4: 20 pts 1. Write a method boolean hasConsecutive (int/ A) that takes an array and returns true if the subtraction of two consecutive
Problem #4: 20 pts 1. Write a method boolean hasConsecutive (int/ A) that takes an array and returns true if the subtraction of two consecutive values in the array is equal to 2 or -2. Otherwise the method returns false For example, if the array is A 4 1 53 47 The difference between 15 and 13 is equal to 2. Here, two consecutive values are found. The method return true. 2. Write a program in which you create an array A of size 6 and fill it with numbers of your choice (you can use the shorthand array initialization). Assume all inputs are positive (do NOT check them in your programi). Your program shall call the above method and prints a message stating whether two consecutive values are found or not Example 1: If the array is 2421 12 141 752 A 4 3 3 4 3 The program displays "There are no consecutive values with difference equals to 2 or -2" Example 2: If the array is A4 35 The program displays "The array has consecutive values with difference equals to 2 or -2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
