Java基础练习 数列特征

版权声明:MZ21G https://blog.csdn.net/qq_35793285/article/details/86420468
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		
		Scanner scanner = new Scanner(System.in);
		int min = Integer.MAX_VALUE;
                // 可能存在负数
		int max = Integer.MIN_VALUE;
		int sum = 0;
		
		while (scanner.hasNext()) {
			
			int num = scanner.nextInt();
			
			for (int i = 0; i < num; i++) {
				
				int temp = scanner.nextInt();
				sum += temp;
				
				if (num == 1) {
					max = min = temp;
				}else {	
					if(max < temp) {
						max = temp;
					}
					if (min > temp) {
						min = temp;
					}	
				}
				
			}
			
			System.out.println(max);
			System.out.println(min);
			System.out.println(sum);
			
		}
		
		
		
	}

}

猜你喜欢

转载自blog.csdn.net/qq_35793285/article/details/86420468