数组的使用
1. For-Each 循环
for (int array : arrays) {
System.out.print(array+"\t");
}
2. 数组做方法入参
//输出数组元素
public static void printArrays(int [] arrays){
for (int i = 0; i < arrays.length; i++) {
System.out.print(arrays[i]+"\t");
}
}
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;
}