题目:将一个数组逆序输出。
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));
}
}
本文介绍了一个简单的Java程序,用于将数组中的元素进行逆序排列并输出。通过使用双指针技术,程序有效地交换了数组首尾元素的位置,实现了逆序效果。

被折叠的 条评论
为什么被折叠?



