- 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] + " ");
- }
- }
- }
来源: http://www.bubuko.com/infodetail-3336620.html