6-6 编程练习 用else if好像也可以做, 但是总感觉不对?
public class HelloWorld {
public static void main(String[] args) {
int[] num={61,23,4,74,13,148,20};
int num_max, num_min, num_avg;
int num_accu = 0;
num_max = num[0];
num_min = num[0];
for (int i=0;i<num.length;i++){
num_accu+=num[i];
if(num[i]>num_max){
num_max = num[i];
}
else if(num[i]<num_min){
num_min = num[i];
}
else{
continue;
}
}
num_avg = num_accu/num.length;
System.out.println("num_max: "+num_max);
System.out.println("num_min: "+num_min);
System.out.println("num_accu: "+num_accu);
System.out.println("Average: "+num_avg);
}
}
我看答案是 用两个if的, 我这样也可以么