数组使用(3种)
package array; public class demo03 { public static void main(String[] args) { int[] array1={1,2,3,4,5}; //JDK1.5,没有下标 //for增强//1.for-each for (int i : array1) { System.out.println(i); } printarray(array1); int[] array2= reverse(array1); printarray(array2); } //打印数组元素//2.数组作为方法入参 public static void printarray(int[] arrays){ for (int i = 0; i < arrays.length; i++) { System.out.println(arrays[i]); } } //反转数组元素//3.数组作为返回值 public static int[] reverse(int[] arrays){ int[] result = new int[arrays.length]; for (int i = 0,j=result.length-1; i <arrays.length ; i++,j--) { result[j]=arrays[i]; } return result; } }