Returns the least value present in array. @param array a nonempty array of int values @return the value present in array that is less than or equal to every other value in the array @throws IllegalArgumentException if array is empty
(int... array)
| 247 | |
| 248 | |
| 249 | public static int min(int... array) { |
| 250 | checkArgument(array.length > 0); |
| 251 | int min = array[0]; |
| 252 | for (int i = 1; i < array.length; i++) { |
| 253 | if (array[i] < min) { |
| 254 | min = array[i]; |
| 255 | } |
| 256 | } |
| 257 | return min; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Returns the greatest value present in {@code array}. |