Returns the greatest value present in array. @param array a nonempty array of int values @return the value present in array that is greater than or equal to every other value in the array @throws IllegalArgumentException if array is empty
(int... array)
| 268 | |
| 269 | |
| 270 | public static int max(int... array) { |
| 271 | checkArgument(array.length > 0); |
| 272 | int max = array[0]; |
| 273 | for (int i = 1; i < array.length; i++) { |
| 274 | if (array[i] > max) { |
| 275 | max = array[i]; |
| 276 | } |
| 277 | } |
| 278 | return max; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Returns the values from each provided array combined into a single array. For example, |