慕仰5913639
2018-03-07 16:20
public class imooc_shuzhu2 {
public static void main(String[] args) {
int[] shuzhu = new int[] { 61, 23, 4, 74, 13, 148, 20 };
int max=shuzhu[0];
int min=shuzhu[0];
double sum=0;
double avg=0;
for(int i=0;i<shuzhu.length;i++){
if(shuzhu[i]>max)
sum=shuzhu[i];
if(shuzhu[i]<min)
min=shuzhu[i];
sum+=shuzhu[i];
}
avg=sum/shuzhu.length;
System.out.println("最小值"+min);
System.out.println("最大值"+max);
System.out.println("平均数"+avg);
}
}
public class Test { public static void main(String[] args) { int[] shuzhu = new int[] { 61, 23, 4, 74, 13, 148, 20 }; int max=shuzhu[0]; int min=shuzhu[0]; int sum=0; double avg=0; for(int i=0;i<shuzhu.length;i++){ if(shuzhu[i]>max) max=shuzhu[i]; if(shuzhu[i]<min) min=shuzhu[i]; sum+=shuzhu[i]; } avg=sum/shuzhu.length; System.out.println("最小值"+min); System.out.println("最大值"+max); System.out.println("平均数"+avg); } }
修改一下圈出的部分看看。
sum=shuzhu[i];改成max=shuzhu[i];
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题
回答 2
回答 1
回答 2
回答 5
回答 1