1. 程式人生 > >傳入一個integer陣列,取出最大、最小值

傳入一個integer陣列,取出最大、最小值

    /**
     * <p>
     * 傳入一個integer陣列,取出最大值
     * </p>
     * @author yunns 2015年11月19日
     * @param array
     * @return max
     */
    private static Integer getMax(Integer[] array) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if
(array[i] > max) max = array[i]; } return max; } /** * <p> * 傳入一個integer陣列,取出最小值 * </p> * @author yunns 2015年11月19日 * @param array * @return max */ private static Integer getMin(Integer[] array) { Integer min
= Integer.MAX_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] < min) min = array[i]; } return min; }