public class HelloWorld{
public static void main(String[] args){
int[] num={61,23,4,74,13,14,8,20};
int sum=0;
int max=num[0];
int min=num[0];
for(int i=0;i<8;i++){
if(max<=num[i])
max=num[i];
else
max=num[0];
if(min<=num[i])
min=num[0];
else
min=num[i];
sum=sum+num[i];
}
int avg=sum/8;
System.out.println("该数组最大值为:"+max);
System.out.println("该数组最小值为:"+min);
System.out.println("和为:"+sum);
System.out.println("平均值为:"+avg);
}
}
4 回答
已采纳
qq_佛说过过过_0
TA贡献17条经验 获得超8个赞
package jav;
public class Hello {
public static void main(String[] args){
int[] num={61,23,4,74,13,14,8,20};
int sum=0;
int max=num[0];
int min=num[0];
for(int i=0;i<8;i++){
if(max<=num[i]) max=num[i];
//else max=num[0];
//if(min>=num[i]) min=num[0];
if(min>=num[i]) min=num[i];
//else min=num[i];
sum=sum+num[i];
}
int avg=sum/8; System.out.println("该数组最大值为:"+max);
System.out.println("该数组最小值为:"+min);
System.out.println("和为:"+sum);
System.out.println("平均值为:"+avg);
}
}
你太粗心了,也不读代码,就拿来问!!!
慕粉void
TA贡献17条经验 获得超7个赞
public class HelloWorld { public static void main(String[] args) { int[] num = {61, 23, 4, 74, 13, 14, 8, 20}; int sum = 0; int max = num[0]; int min = num[0]; for (int i = 0; i < num.length; i++) { if (num[i] > max) max = num[i]; if (num[i] < min) min = num[i]; sum += num[i]; } System.out.println("该数组最大值为:" + max); System.out.println("该数组最小值为:" + min); System.out.println("和为:" + sum); } }
添加回答
举报
0/150
提交
取消