Not passing the testcases

when i compile and test it’s working fine. but when i submit it is not passing the test cases.

Code:

import java.io.;
import java.util.
;
class Main {
public static void rotateMatrix(int N, int mat[][])
{

    for (int x = 0; x < N / 2; x++) {
       
        for (int y = x; y < N - x - 1; y++) {
           
            int temp = mat[x][y];

            
            mat[x][y] = mat[y][N - 1 - x];

    
            mat[y][N - 1 - x]
                = mat[N - 1 - x][N - 1 - y];

            
            mat[N - 1 - x][N - 1 - y] = mat[N - 1 - y][x];

            
            mat[N - 1 - y][x] = temp;
        }
    }
}

// Function to print the matrix
public static void displayMatrix(int N, int mat[][])
{
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++)
            System.out.print(" " + mat[i][j]);

        System.out.print("\n");
    }
    System.out.print("\n");
}

/* Driver program to test above functions */
public static void main(String[] args)
{
	Scanner in = new Scanner(System.in);
    int N = in.nextInt();
	int[][] mat = new int[N][N];
	for(int i=0;i<mat.length;i++)
	{
		for(int j=0;j<mat[i].length;j++)
		{
			mat[i][j]=in.nextInt();
		}
	}
    rotateMatrix(N, mat);


    displayMatrix(N, mat);
}

}

Hi Bharat
In this rotate question what we are required to do is just make the transpose of the matrix and then just print the transpose matrix so try to implement this logic and let me know if you still face any issue.

If we do the transpose, the matrix is reverse of it. I tried it, it’s not coming so I tried in this way. So please guide me in this question.

Hi Bharat Sorry for not replying to your doubt for a long time.
Please try this logic A simple trick that we can observe is that we can first transpose the whole matrix along the leading diagonal and then reverse each row of the matrix. The resulting matrix will be out the rotated matrix.
If you still get any error please let me know

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.