Check out example codes for "in place transpose in a matrix in java". It will help you in understanding the concepts better.

Code Example 1

  //Transpose a Matrix

  for (int row = 0; row < matrix.length; row++) {
    
   for (int col = row; row < matrix[row].length; col++) 
   {
    	// Swap 
     	int data = matrix[row][col];
    	matrix[row][col] = matrix[col][row];
   		matrix[col][row] = data;
   }
  
  }

Learn ReactJs, React Native from akashmittal.com