-
问题链接:最大波动
-
问题分析:模拟法解决。
-
程序说明:n表示数的个数,number数组存数
-
程序代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int[] number = new int[n];
int max;
for(int i=0;i<n;i++) {
number[i]=reader.nextInt();
}
max=Math.abs(number[1]-number[0]);
for(int i=1;i<n-1;i++) {
int temp=Math.abs(number[i+1]-number[i]);
if(temp>max) {
max=temp;
}
}
System.out.print(max);
}
}