Provides extra functionality for Java Number classes.
* * @author Rand McNeely * @author Stephen Colebourne * @author Steve Downey * @author Eric Pugh * @author Phil Steitz * @author Matthew Hawthorne * @author Gary Gregory * @author Fredrik Westermarck * @since 2.0 * @version $Id: NumberUtils.java 609475 2008-01-06 23:58:59Z bayard $ */ public class Main { /** *Returns the maximum value in an array.
* * @param array an array, must not be null or empty * @return the minimum value in the array * @throws IllegalArgumentException ifarray
is null
* @throws IllegalArgumentException if array
is empty
*/
public static long max(long[] array) {
// Validates input
if (array == null) {
throw new IllegalArgumentException("The Array must not be null");
} else if (array.length == 0) {
throw new IllegalArgumentException("Array cannot be empty.");
}
// Finds and returns max
long max = array[0];
for (int j = 1; j < array.length; j++) {
if (array[j] > max) {
max = array[j];
}
}
return max;
}
}