Correct order

  • 7
  • Locked
Let's write a utility for working with arrays. The main functionality is ready: the printArray() method displays all the elements of the array on the console. What is left for you is just a trifle: implement the reverseArray() method. It should reverse the order of the elements in the array. The met
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 9 , Switzerland
20 May, 06:52
One of the best ways techniques is to store index 0 temporarily. Then assign to index zero the value of the last index. After that assign the temporarily stored index 0 to the last index. Visually you basically come from both sides until you are in the middle.
Level 13 , Ilmenau, Germany
21 December 2022, 14:23
So lines 24 to 26 are delivering the right result + pass the verification and I cannot understand why. My original code in line 27 has to work exactly as code in 24..26 do. At least I think so. I supposed line 27 does not work, as array[] exists only in the main() and I cannot change it from reverseArray(). Am I working with references here? If so, why does line 27 not works? lines 24..26: for (int i = 0; i < array.length; i++) { array[i] = reverse[i]; } line 27: //array = Arrays.copyOf(reverse, reverse.length);
Level 22 , San Diego, United States
9 December 2021, 05:29
There are other techniques / methods to solve this. Print the Elements of an Array in Reverse Order. No need to use an additional array, and it is not converted into an array list. Instead the array elements are put into reverse order in-place. This means that they are, in fact, swapped.