Рет қаралды 1,654
Rotate Matrix by 90 Degrees in Java | Rotate Matrix in Java Clockwise and Anti-clockwise , Transpose of matrix
Contact at - 9555031137
Website - www.prateekjainacademy.com
In this section, we will create a Java program to rotate a matrix by 90 degrees in a clockwise and anti-clockwise rotation. The clockwise rotation is also known as the right rotation of the matrix and the anti-clockwise rotation of the matrix is also known as the left rotation of the matrix.
Rotate Matrix 90 Degree Clockwise or Right Rotation
The rotation of a matrix involves two steps:
First, find the transpose of the given matrix.
Swap the elements of the first column with the last column (if the matrix is of 3*3). The second column remains the same.
It is an efficient solution.
If the given matrix is 4*4 matrix, swap the first column with the last column and the second column with the third column.