public class swapElement {
public static void main(String[] args) {
int[] a = {10,20,30,40,50,60};
for (int i = 0, j = a.length-1;i < j; i++,j--) {
int temp = a[j];
a[j]=a[i];
a[i]=temp;
}
System.out.println("前后元素调换后数组:");
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+"\t");
}
}
}
运行结果:

该文章展示了如何使用Java编写一个名为`swapElement`的公共类,通过for循环实现数组中前后元素的交换,并打印出调换后的数组。
3048

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



