Write a method called minGap that accepts an integer array as a parameter and returns the minimum
Question:
Write a method called minGap that accepts an integer array as a parameter and returns the minimum difference or gap between adjacent values in the array, where the gap is defined as the later value minus the earlier value. For example, in the array [ 1, 3, 6, 7, 12 ], the first gap is 2 (3 − 1), the second gap is 3 (6 − 3), the third gap is 1 (7 − 6), and the fourth gap is 5 (12 − 7). So your method should return 1 if passed this array. The minimum gap could be a negative number if the list is not in sorted order. If you are passed an array with fewer than two elements, return 0.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted: