Java-数组 求最大最小平均值

 

int[] array = {9,3,4,6,8,28,15,33};
int max = array[0];
for(int x:array){
if (x>=max){
max = x;
}
}
System.out.println(max);

int min = array[0];
for (int j:array){
if (j<=min){
min = j;
}
}
System.out.println(min);

double sum = 0.0;
for (int y:array){
sum = sum + y;
}
System.out.println(sum/array.length);
posted @ 2021-12-27 15:15  小小生Sir  阅读(290)  评论(0编辑  收藏  举报