找出数组中的最大值和最小值

public class ArrayMaxAndMin {
public static void main(String[] args) {
    int[] array = { 1, 3, 6, 4, 9, 7, 0 };
    System.out.println("Max is :" + getMax(array));
    System.out.println("Max is :" + getMin(array));
}

public static int getMax(int[] array) {
    int Max = array[0];
    for (int i = 1; i < array.length; i++) {
        if (Max < array[i]) {
            Max = array[i];
        }
    }
    return Max;
}

public static int getMin(int[] array) {
    int Max = array[0];
    for (int i = 1; i < array.length; i++) {
        if (Max > array[i]) {
            Max = array[i];
        }
    }
    return Max;
}
}

你可能感兴趣的:(找出数组中的最大值和最小值)