java数组元素对称调换

package com.it.homework;

import java.util.Arrays;

public class TestEleChangePosition {
	
	public static void main(String[] args) {
		int[] arr = {0,1,2,3,4,5,6,7,8,9};
		System.out.println(Arrays.toString(arr));
		symmetricElement(arr);
		System.out.println(Arrays.toString(arr));
	}

	private static void symmetricElement(int[] arr) {
		for (int i = 0; i < arr.length/2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length-1-i];
			arr[arr.length-1-i] = temp;
		}
	}

}

在这里插入图片描述

发布了37 篇原创文章 · 获赞 29 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_42755868/article/details/105031872