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 byte max(byte[] 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
byte max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
}