How do I get the max and min values from a set of numbers entered?

后端 未结 8 1023
终归单人心
终归单人心 2020-11-28 15:52

Below is what I have so far:

I don\'t know how to exclude 0 as a min number though. The assignment asks for 0 to be the exit number so I need to have the lowest numb

8条回答
  •  遥遥无期
    2020-11-28 16:46

    This is what I did and it works try and play around with it. It calculates total,avarage,minimum and maximum.

    public static void main(String[] args) {
       int[] score= {56,90,89,99,59,67};
       double avg;
       int sum=0;
       int maxValue=0;
       int minValue=100;
    
       for(int i=0;i<6;i++){
           sum=sum+score[i];
       if(score[i]maxValue){
        maxValue=score[i];
       }
       }
       avg=sum/6.0;
    System.out.print("Max: "+maxValue+"," +" Min: "+minValue+","+" Avarage: "+avg+","+" Sum: "+sum);}
    
     }
    

提交回复
热议问题