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

后端 未结 8 1029
终归单人心
终归单人心 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:30

    You just need to keep track of a max value like this:

    int maxValue = 0;
    

    Then as you iterate through the numbers, keep setting the maxValue to the next value if it is greater than the maxValue:

    if (value > maxValue) {
        maxValue = value;
    }
    

    Repeat in the opposite direction for minValue.

提交回复
热议问题