Problem Description
求n个整数中的绝对值最大的数。
Input
输入数据有2行,第一行为n,第二行是n个整数。
Output
输出n个整数中绝对值最大的数。
Sample Input
5 -1 2 3 4 -5
Sample Output
-5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int[] a = new int[100];
int n = reader.nextInt();
for(int i=0; i<n; i++) {
a[i] = reader.nextInt();
}
int max=0 , k=0;
for(int i=0; i<n; i++) {
if(Math.abs(a[i])>=max) {
max = Math.abs(a[i]);
k=i;
}
}
System.out.println(a[k]);
}
}