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

后端 未结 10 1993
天涯浪人
天涯浪人 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 11:20

    A way to do it would be using the java.util.Arrays class:

    Example:

    public class ArraySort {
    public static void main(String[] args) {
        int[] array = {12, 4, 6, 1, 56, 21, 77};
        Arrays.sort(array);
        System.out.println(array[0]);
    }
    }
    

    From the Java doc, Arrays.sort(int[]) sort the specified array into ascending numerical order.

    So the output here prints 1.

提交回复
热议问题