Javaopp找最大值的方法,传入一个有值数组

img

public class Test {
    /**
     * 输出数组中的最大值
     * @param nums
     * @return
     */
    public int max(int[] nums) {
        int max = Integer.MIN_VALUE;
        for (int num : nums) {
            max = Math.max(max, num);
        }
        System.out.println(max);
        return max;
    }

    /**
     * 测试
     * @param args
     */
    public static void main(String[] args) {
        Test t = new Test();
        int[] nums = new int[]{1,3,5,7,2,4,6};
        System.out.println("最大值是:"+t.max(nums));
    }
}

img