Purpose:
First create an array with a length of 5, then assign a random integer to each bit of the array, and find the smallest (largest) value come out.
Method 1:
int array[] = new int[5]; System.out.println("数组的元素为:"); for (int i=0;iarray[i]){ min=array[i]; } } System.out.println("方法二:最小值为:"+min); }
Result:
java quick start)
Method 2:int array[] = new int[5]; System.out.println("数组的元素为:"); for (int i=0;iResult:
##Method 3:
Collections through Collections class .max() and Collections.min() methods to find the maximum and minimum values in an array.
The code is as follows:
Integer array[] = new Integer[5]; System.out.println("数组的元素为:"); for (int i=0;iResult:
## Recommended related video tutorials:java video tutorial
The above is the detailed content of How to implement the minimum value in an array in java. For more information, please follow other related articles on the PHP Chinese website!