package com.JH.array;
import java.security.PublicKey;
public class JH04 {
public static void main(String[] args) {
int[] arrays = {1,2,3,4,5};
// for(int array : arrays){
// System.out.println(array);
// }
//printArray(arrays);
//reverse(arrays);
int[] reverse = reverse(arrays);
printArray(reverse);
}
//反转数组
// public static int[] reverse(int arrays[]){
// int[] result = new int[arrays.length];
// //反转操作
// for (int i = arrays.length-1; i >= 0; i–) {
// result[i] = arrays[arrays.length-i];
// }
// return result;
// }
public static int[] reverse(int arrays[]) {
int[] result = new int[arrays.length];
//反转操作
for (int i = 0, j = result.length - 1; i < result.length; i++, j–) {
result[j] = arrays[i];
}
return result;
}
//打印数组元素
public static void printArray(int[] arrays){
for (int i = 0; i < arrays.length; i++) {
System.out.print(arrays[i]+" ");
}
}
}