试题 基础练习 数列特征
资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
给出n个数,找出这n个数的最大值,最小值,和。
输入格式
第一行为整数n,表示数的个数。
第二行有n个数,为给定的n个数,每个数的绝对值都小于10000。
输出格式
输出三行,每行一个整数。第一行表示这些数中的最大值,第二行表示这些数中的最小值,第三行表示这些数的和。
样例输入
5
1 3 -2 4 5
样例输出
5
-2
11
数据规模与约定
1 <= n <= 10000。
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int max = 0;
int min = 0;
int sum = 0;
int input = scan.nextInt();
for (int i = 0; i < input; i++) {
int temp = scan.nextInt();
if (i == 0){
max = temp;
min = temp;
}else if(max < temp){
max = temp;
}else if(min > temp){
min = temp;
}
sum += temp;
}
System.out.println(max);
System.out.println(min);
System.out.println(sum);
}
}