JAVA经典算法(三十一)

  题目:将一个数组逆序输出。

package cn.ls.lanqiao;

import java.util.*;

public class Test31 {

	public static void main(String[] args) {
		int[] a = new int[] { 7, 6, 5, 4, 3, 2, -1 };
		int temp;
		for (int i = 0; i < a.length / 2; i++) {
			temp = a[i];
			a[i] = a[a.length - 1 - i];
			a[a.length - 1 - i] = temp;
		}
		System.out.println(Arrays.toString(a));
	}
}
发布了147 篇原创文章 · 获赞 160 · 访问量 9362

猜你喜欢

转载自blog.csdn.net/ls_wifi/article/details/104079839