There is an array [1,2,3,4,5,6,7] , you need to bring it to the form [5,6,7,4,1,2,3] .

As I understand it, this is done in 2 cycles: in one, we run from i = 0 to the middle of the array ( middleArray ) and in the second from j = middleArray + 1 to the end. Save the value x = arr[i] , then arr[i] = arr[j] , Π·Π°Ρ‚Π΅ΠΌ arr[j] = x . This is how my thoughts go. Is this right?

  • What is the problem? - temq

1 answer 1

 public static void main (String[] args){ int[] array = {1, 2, 3, 4, 5, 6, 7}; if (array.length < 2) return; //Π½Π°Ρ…ΠΎΠ΄ΠΈΠΌ сСрСдину массива int border = (array.length + 1) / 2; //мСняСм мСстами элСмСнты массива for (int i = 0; i < array.length / 2; i++){ int temp = array[i]; array[i] = array[border + i]; array[border + i] = temp; } } 
  • thank you very much! it was enough just to describe the algorithm in words, but it’s good too =) - Arthur