public class MethodDemo9 { /** * 可变参数 * * @param num */ public static void test(int... num) { //先判断是否有值? if (num != null && num.length > 0) { int sum = 0; for (int i : num) { System.out.print(i + " "); sum += i; } System.out.println("和:" + sum); } System.out.println("------------------------------------------------"); } /** * 固定参数 * * @param a */ public static void test(int a) { System.out.println("test-->" + a); } /** * 测试 * * @param args */ public static void main(String[] args) { test(); test(null); test(10); //优先调用固定参数 test(10, 20); test(10, 20, 30); } }
标签:int,System,num,参数,可变,test,public,out From: https://www.cnblogs.com/19981206-zxb/p/16896505.html