public class ArrayDemo03 {public static void main(String[] args) {int[] arrays = {1,2,3,4,5};// JDK1.5, 没有下标,增强写法
// for (int array : arrays) {
// System.out.println(array);
// }printArray(arrays);System.out.println("============");int[] reverse = reverse(arrays);printArray(reverse);
// for (int i : reverse) {
// System.out.println(i);
// }}// 反转数组public static int[] reverse(int[] arrays){int[] result = new int[arrays.length];// 反转操作
// for (int i = arrays.length - 1; i >= 0; i--) {
// result[(arrays.length - 1)-i] = arrays[i];
// }for (int i = 0,j=result.length-1; i < arrays.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]+" ");}}
}
https://www.bilibili.com/video/BV12J41137hu?p=55&spm_id_from=pageDriver