博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java可变参数
阅读量:2386 次
发布时间:2019-05-10

本文共 666 字,大约阅读时间需要 2 分钟。

 

//int(type) followed ... (three dot's) is syntax of a variable argument.    public static int sum(int... numbers) {        //inside the method a variable argument is similar to an array.        // number can be treated as if it is declared as int[] numbers;        int sum = 0;        for (int number : numbers) {            sum += number;        }        return sum;    }    public static void main(String[] args) {        // 3 Arguments        System.out.println(sum(1, 4, 5)); // 10        // 4 Arguments        System.out.println(sum(1, 4, 5, 20));//30        // 0 Arguments        System.out.println(sum()); // 0    }

 

posted @
2018-01-22 17:12 阅读(
...) 评论(
...)

转载地址:http://pkjab.baihongyu.com/

你可能感兴趣的文章
给一个正在运行的Docker容器动态添加Volume
查看>>
关于Docker目录挂载的总结
查看>>
docker 主机 容器通信
查看>>
wkhtmltopdf 中文参数详解
查看>>
odoo 中 wkhtmltopdf 页码的读取(js)
查看>>
用 strcoll 实现中文按拼音排序
查看>>
linux adduser-s /sbin/nologin和/bin/false的区别
查看>>
linux 修改用户的shell
查看>>
浅析ATO,MTO和ETO
查看>>
Python多进程不要使用TimedRotatingFileHandler
查看>>
CSS语法和CSS优先级
查看>>
undercore.js 的几个方法
查看>>
python 类和元类(metaclass)的理解和简单运用
查看>>
git commit id相关
查看>>
odoo 慎用related(计算字段)
查看>>
psql pg_dump pg_restore等命令
查看>>
sql重复数据处理
查看>>
Python str(float) 科学计数法
查看>>
git 命令整理
查看>>
Python__slots__详解
查看>>