Question: java (b) Write the Mountain method isMountain. Method isMountain returns true if the values in the parameter array are ordered as a mountain; otherwise, it
java

(b) Write the Mountain method isMountain. Method isMountain returns true if the values in the parameter array are ordered as a mountain; otherwise, it returns false. The values in array are ordered as a mountain if all three of the following conditions hold. There must be a peak. The array elements with an index smaller than the peaks index must appear in increasing order. The array elements with an index larger than the peak's index must appear in decreasing order. . . . For example, the following table illustrates the results of several calls to isMountain. arr isMountain (arr) {1, 2, 3, 2, 1} true false false {1, 2, 1, 2, 1} {1, 2, 3, 1, 5} {1, 4, 2, 1, 0} {9, 3, 5, 7, 5} true false {3, 2, 1) false In writing isMountain, assume that get PeakIndex works as specified, regardless of what you wrote in part (a). Complete method isMountain below. * /** @param array an array of positive integer values Precondition: array.length > 0 @return true if array contains values ordered as a mountain; false otherwise * * public static boolean isMountain (int[] array)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
