X573: minDiff

This method takes an integer array as a parameter and returns the minimum difference between adjacent values in the array. The difference between two adjacent values in an array is defined as the second value minus the first value. For example, if array stores the following sequence of values: {3, 5, 11, 4, 8}, the differences would be computed as 5 – 3 = 2, 11 - 5 = 6, 4 - 11 = -7, 8 - 4 = 4. Of these values, -7 is the smallest, so it would be returned. If an array has less than 2 elements, the method should return 0.

Examples:

minDiff({3, 5, 11, 4, 8}) -> -7

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.