public class ArrayDemo2 {
public static void main(String[] args) {
//定义一个数组存放元素
int[] arr3 = {10, 20, 30, 40, 50, 60, 70, 80, 90};
//arr3.length/2 需要互换的次数
for (int i = 0; i < arr3.length / 2; i++) {
//进行数组互换
int sum = arr3[i];
arr3[i] = arr3[arr3.length - 1 - i];
arr3[arr3.length - 1 - i] = sum;
}
for (int i = 0; i < arr3.length; i++) {//重新遍历一次数组
System.out.print(arr3[i] + " ");
}
}
}
Java中数组的反转
最新推荐文章于 2024-09-06 18:50:44 发布