Question: Copy the program ValleyPeakPlateau.java to your computer and implement the method named valley_peak_plateau(int[]) . The static void valley_peak_plateau(int[] a) method prints to the standard output
Copy the program ValleyPeakPlateau.java to your computer and implement the method namedvalley_peak_plateau(int[]).
The static void valley_peak_plateau(int[] a) method prints to the standard output stream the valleys, peaks, and plateaus found in the int[] a parameter. Only arrays having two or more elements are processed.
The following are definitions for valley, peak, and plateau. Note: A plateau is when a number occurs three or more consecutive times in an array.
note: int[] a ... an array of ints of named a int n ... the length of array a, where n 2 int i ... index into array a when i is 0 a[i] is valley if a[i] less than a[i+1] a[i] is peak if a[i] greater than a[i+1] a[i] is plateau if a[i] equals a[i+1] and a[i+2] when 0 < i < n - 1 a[i] is valley if a[i] is less than both a[i-1] and a[i+1] a[i] is peak if a[i] is greater than both a[i-1] and a[i+1] a[i] is plateau if a[i] equals both a[i-1] and a[i+1] note: a[i-1] is the start of the plateau and the plateau ends when the number changes (or end of array is reached) -- see the output if clarification is needed when i is n - 1 a[i] is valley if a[i] less than a[i-1] a[i] is peak if a[i] greater than a[i-1] a[i] is plateau if a[i] equals a[i-1] and a[i-2]
ValleyPeakPlateau program:
public class ValleyPeakPlateau { public static void main(String[] argv) { int[][] arrays = { { 3, 5, 4, 4, 4, 4, 2, 6, 5, 5, 5, 5, 4, 4, 4, 4, 7, 2, 4, 6, 5 }, { 9, 9, 9, 9, 9, 4, 7, 9, 9, 9, 9, 2, 9, 9, 9, 9, 9 }, { 0, 5, 7, 7, 7, 4, 8, 7, 7, 7, 10, 2, 6 }, { 2, 8, 8, 8, 7, 9, 9, 9, 9, 9, 3, }, { 1, 9, 3, 5, 2, 7, 3, 5, 1, }, { 2, 5, 3, 2, 1, 9, 7, 8, }, { 4, 4, 7, 4, 4, 4, 2, }, { 2, 5, 3, 3, 7, 2, }, { 1, 1, 1, 2, 0, 9, }, { 9, 0, 2, 1, 1, 1, }, { 1, 2, 3, 3, 2, 1, }, { 1, 2, 5, 9, 10, }, { 4, 3, 2, 1, 0, }, { 7, 7, 7, 7, }, { 6, 5, 5, 5 }, { 3, 3, 3, 9 }, { 1, 3, 2, }, { 3, 2, 1, }, { 1, 2, }, { 7, 5, }, { 6, 6, }, { 1, }, { }, }; for (int i = 0; i < arrays.length; i++) valley_peak_plateau(arrays[i]); } /* * TBI (To Be Implemented)... * * */ static void valley_peak_plateau(int[] a) { } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
