代码
import java.util.Scanner;// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int n = in.nextInt();int[] array = new int[n+1];//此处n+1 防止后面判断i+1下标时数组越界for(int i = 0; i < n; i++){array[i] = in.nextInt();}int i = 0;int count = 0;while(i < n){if(array[i] > array[i+1]){while(i < n && array[i] > array[i + 1]){i++;}count++;i++;}else if(array[i] == array[i+1]){i++;}else{while(i < n && array[i] < array[i + 1]){i++;}count++;i++;}}System.out.print(count);}
}