数组的使用
- 普通for循环
- For-Each循环
- 数组作为方法入参
- 数组作为返回值
package com.etc;
public class ArrayDemo {
public static void main(String[] args) {
int[] arrays = {1,2,3,4,5};
int[] reverse = reverse(arrays);
printArray(reverse);
}
public static int[] reverse(int[] array){
int[] result = new int[array.length];
for (int i = 0,j = result.length-1; i<array.length; i++,j--){
result[j] = array[i];
}
return result;
}
public static void printArray(int[] arrays){
for(int i = 0; i<arrays.length; i++){
System.out.println(arrays[i]+" ");
}
}
}