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 (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Pavlo
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);
Hoist
Level 30 , 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. https://codegym.cc/groups/posts/reverse-an-array-in-java?fbclid=IwAR0LpZd6qKVhB2flrPndudf8isJ4V4Hyw1QX9Z7xacHNu2mgZOna-RUbwiU