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

后端 未结 10 1988
天涯浪人
天涯浪人 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:01

    One option is sort your array and get the first element:

    import java.util.Arrays;
    
    ...
    
    int ints[] = {30,5,7,4,10};
    Arrays.sort(ints);
    
    int min = ints[0];
    int max = ints[ints.length - 1];
    

提交回复
热议问题