Finding the minimum value of int numbers in an array (Java)

后端 未结 10 1976
天涯浪人
天涯浪人 2020-12-22 10:42

I\'m trying to find the minimum value of numbers in an array but it doesn\'t always work out properly. This is the code I wrote:

        for (int i=0; i <         


        
10条回答
  •  执念已碎
    2020-12-22 11:24

    You are checking the first element in each iteration, you basically need to check minimum value

    if (arr[j] < min) {
      min = arr[j];
    }
    

提交回复
热议问题