Assignment: #ValleyPeak |
Due: 02/11/2017 |
Points: 3 |

Copy the program ValleyPeak.java to your computer and implement the method named

valley_peak().The

static void valley_peak(int[] a)method prints to the standard output stream the valleys and peaks found in theintarray that it receives as a parameter.Here are the definitions for valleys and peaks.

the following three valley/peak definitions use the variables: int[] a ... an array of ints int n ... the length of array a 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] 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] 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]Example.

array: { 2 5 3 2 1 9 7 8 } n: 8 a[0]=2 is a valley a[1]=5 is a peak a[4]=1 is a valley a[5]=9 is a peak a[6]=7 is a valley a[7]=8 is a peakAdditional examples and what the output of this program should be are found in ValleyPeak.java.