package com.xiao.parameter; public class Demo { public static void main(String[] args) { Demo demo = new Demo(); demo.test(1,2,3,4); demo.test(2,3); demo.test(3,4,52.2); demo.test(new double[]{1,2,3});//可变参数的写法,里面就相当于数组 } //可变参数的写法,里面就相当于数组 public void test(int...i){ System.out.println(i[0]); System.out.println(i[1]); System.out.println(i[2]); System.out.println(i[3]); } //对应不同参数类型 /* public void test(int ...i,int j); 这样写是错误的,要像下面这样写把可变参数放在后面 */ // public void test(int y,int...i){}这句是对的,为了程序不报错我注释掉 public void test(double y,int...i){} public void test(double ... x){} }
微信扫码关注
更新实时通知