输入6个整数,先将其输出然后再将数组倒转,再次输出数组
public static void main(String[] args) {
int[] arr = new int[6];
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
arr[i] = scanner.nextInt();
}
System.out.println(Arrays.toString(arr));
//write your code here......
int left = 0, right = arr.length - 1; //双指针从首尾开始
while(left < right){
int temp = arr[left]; //交换指针元素
arr[left] = arr[right];
arr[right] = temp;
left++; //指针向中间靠
right--;
}
System.out.println(Arrays.toString(arr));
}