- class VarargsDemo{
- public static void main(String[] args) {
- printMany1();//也可以不传入参数
- printMany1(1);
- printMany1(2,3);
- printMany1(4,5,6);
- }
- public static void printMany1(int... varargs){
- for (int i=0;i<varargs.length;i++ ) {
- System.out.print(varargs[i]+" ");
- }
- System.out.println();
- }
- }
复制代码
虽然学了,但是不知道什么时候用? |
|