I have edited a java method for finding peaks by comparing its neighboring elements. But I have a problem in storing the values in the output array...
Here is the method that is edited, commented is my problem
public static int[] peakInArray(int[] arr2){
int i;
int lenghtInput = arr2.length;
int[] peaks = new int[lenghtInput];
for (i = 1; i<arr2.length - 1; i++) {
if (arr2[i] > arr2[i - 1] && arr2[i] > arr2[i + 1]);
// PROBLEM: store arr2[i] in peaks
peaks[i] = arr2[i];
}
return peaks;
}
if(...);the;at the end makes thisifstatement useless.;with{}, like yourforloop) is likely the solution. If you notice other problems, please post more detailed info about what the actual problem is.