用绝对值,后一天减去前一天即可
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
}
int max = Math.abs(a[1] - a[0]);
for(int j=1;j<n-1;j++) {
if(Math.abs(a[j+1] - a[j]) > max) {
max = Math.abs(a[j+1] - a[j]);
}
}
System.out.println(max);
}
}