Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

D casch 13 V10 Find the other the trigonometrte ration of 10 10

Answered: 1 week ago