import java.util.*;
public class demo {
public static void main(String[] args) {
System.out.println("请输入若干个数,每输入一个数回车确认");
System.out.println("最后输入数字-1结束输入操作");
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
int count = 0;
int i ;
while((i=sc.nextInt())!=-1){
list.add(i);
count+=i;
}
Collections.sort(list);
int max = list.get(list.size()-1);
int min = list.get(0);
double avg = count*1.0/list.size();
System.out.println("最大值"+max);
System.out.println("最小值"+min);
System.out.println("平均值"+avg);
}
}
楼上的回答也可以,我这是另一种方法,看起来更明了一点,可以供你参考,喜欢的话请采纳~