数组的遍历
数组的遍历:
class Hello2 { public static void main(String[] args) { int[] arr = {11,12,13,14,15}; for (int i = 0;i < arr.length ;i++ ) { System.out.println(arr[i]); } } }
结果:
用方法来实现数组的遍历:
class Hello2 { public static void main(String[] args) { int[] arr1 = {11,12,13,14,15}; print(arr1); } public static void print(int[] arr) { for (int i = 0;i < arr.length ;i++ ) { System.out.print(arr[i] + " "); } } }
结果:
相关文章