问题描述
小明正在利用股票的波动程度来研究股票。小明拿到了一只股票每天收盘时的价格,他想知道,这只股票连续几天的最大波动值是多少,即在这几天中某天收盘价格与前一天收盘价格之差的绝对值最大是多少。
输入格式
输入的第一行包含了一个整数n,表示小明拿到的收盘价格的连续天数。
第二行包含n个正整数,依次表示每天的收盘价格。
输出格式
输出一个整数,表示这只股票这n天中的最大波动值。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner in=new Scanner(System.in);
Short n=in.nextShort();
short first=in.nextShort();
short second=in.nextShort();
short result=(short)Math.abs(first-second);
for(int i=3;i<n;i++) {
first=second;
second=in.nextShort();
short temp=(short)Math.abs(first-second);
result=result<temp?temp:result;
}
System.out.print(result);
in.close();
}
}