posts - 45,comments - 0,views - 4815
复制代码
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);
    }
}
复制代码

 

posted on   小贤看世界  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示