What will be the output of the following code? -------------------- public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5, 6}; int left = 0; int right = arr.length - 1; while (left < right) { int temp = arr[left]; arr[left+=2] = arr[right]; arr[right-=2] = temp; } System.out.println(Arrays.toString(arr)); }
Geekific
What will be the output of the following code?
--------------------
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6};
int left = 0;
int right = arr.length - 1;
while (left < right) {
int temp = arr[left];
arr[left+=2] = arr[right];
arr[right-=2] = temp;
}
System.out.println(Arrays.toString(arr));
}
1 week ago | [YT] | 2