数组作为方法参数
作者:互联网
1 /* 2 数组可以作为方法的参数。 3 当调用方法的时候,向方法的小括号进行传参,传递进去的其实是数组的地址值。 4 */ 5 public class Demo01ArrayParam { 6 7 public static void main(String[] args) { 8 int[] array = { 10, 20, 30, 40, 50 }; 9 10 System.out.println(array); // 地址值 11 12 printArray(array); // 传递进去的就是array当中保存的地址值 13 System.out.println("==========AAA=========="); 14 printArray(array); 15 System.out.println("==========BBB=========="); 16 printArray(array); 17 } 18 19 /* 20 三要素 21 返回值类型:只是进行打印而已,不需要进行计算,也没有结果,用void 22 方法名称:printArray 23 参数列表:必须给我数组,我才能打印其中的元素。int[] array 24 */ 25 public static void printArray(int[] array) { 26 System.out.println("printArray方法收到的参数是:"); 27 System.out.println(array); // 地址值 28 for (int i = 0; i < array.length; i++) { 29 System.out.println(array[i]); 30 } 31 } 32 33 }
标签:printArray,int,System,参数,数组,println,array,方法,out 来源: https://www.cnblogs.com/zrwx/p/13875016.html