/* 问题描述 给出n个数,找出这n个数的最大值,最小值,和。 输入格式 第一行为整数n,表示数的个数。 第二行有n个数,为给定的n个数,每个数的绝对值都小于10000。 输出格式 输出三行,每行一个整数。第一行表示这些数中的最大值,第二行表示这些数中的最小值,第三行表示这些数的和。 样例输入 5 1 3 -2 4 5 样例输出 5 -2 11 数据规模与约定 1 <= n <= 10000。 */
package com.basedOnPractice;
/**
* @author 鱼骨头
* @version jdk-17 2022-03-01
*/
import java.util.Scanner;
public class Sequence_Characteristics {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//输入需要查找的整数个数
int n = input.nextInt();
int[] array = new int[n];
//从键盘获取需要的处理的数据
for (int i = 0; n > i; i++) {
int num = input.nextInt();
array[i] = num;
}
//处理数据
for (int i = 1; i < n; i++) {
int result = 0;
//对数组进行升序排序
if(!(array[i - 1] <= array[i])){
result = array[i-1];
array[i - 1] = array[i];
array[i] = result;
}
}
//遍历数组array并打印
for (int i = 0; i < n; i++) {
System.out.print(array[i]+" ");
}
System.out.println();
System.out.println(array[n-1]);
System.out.println(array[0]);
//求和处理
int add = 0;
for (int i = 0; i < n; i++) {
add = add+array[i];
}
System.out.println(add);
}
}
************注意************
该程序有点小bug,输入题干数据会出现1 -2 3 4 5即-2与1未能比较出。输入其他数据目前没有发现相关问题