public class Demo04 {public static void main(String[] args) {// 调用可变参数的方法printMax(34, 3, 3, 2, 56.5);printMax(new double[]{1, 2,4, 3});}public static void printMax(double... numbers) {if (numbers.length == 0){System.out.println("没有传递参数");return;}double result = numbers[0];// 排序for (int i = 1; i < numbers.length; i++) {if (numbers[i] > result){result = numbers[i];}}System.out.println("最大值是: " + result);}}
https://www.bilibili.com/video/BV12J41137hu?p=49&spm_id_from=pageDriver