static void reverseColumns(int arr[][])
{
for (int i = 0; i < arr[0].length; i++)
for (int j = 0, k = arr[0].length - 1;
j < k; j++, k–) {
int temp = arr[j][i];
arr[j][i] = arr[k][i];
arr[k][i] = temp;
}
}
How this is working
hi @pallavigoel1996
it similar to reversing an array
for any row i
j is at 0 index and k is at array length-1
just swap elements
and increase j and decease k simultaneously
this process will continue till middle index after that it will terminate
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.