I am fairly new to this an am unable to wrap my head around this. I have basically been given a 4x4 array such as:
5 2 1 7
3 2 4 4
7 8 9 2
1 2 4 3
I am trying to reverse specific rows, I am stuggling to find anything online about doing it for specific rows so I was wondering if anyone could give me an idea on how I could approach this.
the desired output would be if a user asked for row 0 to be reversed then it would return
7 1 2 5
3 2 4 4
7 8 9 2
1 2 4 3
i have attempted it but my code is not working. This is my code:
for(int i = 0; i < row; i++){
for(int col = 0; col < cols / 2; col++) {
int temp = arr[i][col];
arr[i][col] = arr[i][arr[i].length - col - 1];
arr[i][arr[i].length - col - 1] = temp;
}
Thanks in advance!