使用遗传算法设计程序

设计一个遗传算法计算函数最大值();1、计算函数最大值程序 2,计算函数最小值程序


public class test {
    static int getMin(int[] nums) {
        int min = Integer.MAX_VALUE;
        for (int item : nums) {
            min = Math.min(item, min);
        }
        return min;
    }

    static int getMax(int[] nums) {
        int max = Integer.MIN_VALUE;
        for (int item : nums) {
            max = Math.max(item, max);
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3, 4, 7, 2, -1, 98, 32, 13, 62, 67, -55};
        System.out.println("max = " + getMax(nums));
        System.out.println("min = " + getMin(nums));
    }
}

运行结果:

img