Finding the index number of the lowest value in an array

后端 未结 4 821
借酒劲吻你
借酒劲吻你 2021-01-21 22:32

I have to return the index number of the lowest value in an array of 12 numbers. I keep getting 12 as the result every time I run it. Here is my code:

minRain =          


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 23:12

    What is the meaning of this statement?

    int lowest = (int) mon4[0];
    

    You are saving the first value of the array as the lowest one and then later comparing with array values. You are actually comparing index with array values.

    if (mon4[index]

    You should do something like this.

     if (mon4[index]

提交回复
热议问题