package com.fgy.demo; /** * 数组元素反转 */ public class demo05 { public static void main(String[] args) { int[] arr = {10, 20, 30, 40, 50}; System.out.print("数组反转前:"); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } System.out.println(); for(int min = 0, max = arr.length - 1; min < max; min++, max--) { int temp = arr[min]; arr[min] = arr[max]; arr[max] = temp; } System.out.print("数组反转后:"); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } } }
原文地址:https://www.cnblogs.com/roadlandscape/p/12057073.html
时间: 2024-10-08 09:22:12