问题描述
给出n个数,找出这n个数的最大值,最小值,和。
输入格式
第一行为整数n,表示数的个数。
第二行有n个数,为给定的n个数,每个数的绝对值都小于10000。
输出格式
输出三行,每行一个整数。第一行表示这些数中的最大值,第二行表示这些数中的最小值,第三行表示这些数的和。
样例输入
5
1 3 -2 4 5
1 3 -2 4 5
样例输出
5
-2
11
-2
11
数据规模与约定
1 <= n <= 10000。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main{
public static void main(String[] args) throws IOException {
String str1 = null;
String str2 = null;
int sum = 0;
int n = 0;
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
str1 = bfr.readLine();
n = Integer.parseInt(str1);
str2 = bfr.readLine();
String [] arr = str2.split(" ");
int [] arr2 = new int[n];
for(int i=0; i<n; i++){
arr2[i] = Integer.parseInt(arr[i]);
sum += arr2[i];
}
Arrays.sort(arr2);
System.out.println(arr2[n-1]);
System.out.println(arr2[0]);
System.out.println(sum);
}
}