Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:

    public static void main(String[] args) {
        // To take Inputs From the User
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of rows in the 2D matrix:");
        int row = sc.nextInt();
        System.out.println("Enter the number of columns in the 2D matrix:");
        int column = sc.nextInt();
        int[][] arr = new int[row][column];
        System.out.println("Enter the elements");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        // To Print the Original MAtrix
        System.out.println("The Original matrix is:");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.print("\n");
        }
        // Calling Function Mirror
        Mirror(arr);
    }
}


Review comment (suggestion):
```suggestion
```
Please remove the `main` method and instead add some proper tests. Good examples to look at:
- [`Factorial`](https://github.com/TheAlgorithms/Java/blob/566c27a996f48a94916170c159ae735546b39c42/src/main/java/com/thealgorithms/maths/Factorial.java) and [`FactorialTest`](https://github.com/TheAlgorithms/Java/blob/566c27a996f48a94916170c159ae735546b39c42/src/test/java/com/thealgorithms/maths/FactorialTest.java),
- [`FindMax`](https://github.com/TheAlgorithms/Java/blob/566c27a996f48a94916170c159ae735546b39c42/src/main/java/com/thealgorithms/maths/FindMax.java) and [`FindMaxTest`](https://github.com/TheAlgorithms/Java/blob/566c27a996f48a94916170c159ae735546b39c42/src/test/java/com/thealgorithms/maths/FindMaxTest.java).


Code after:
package com.thealgorithms.misc;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
    }
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
        for (int i = 0; i < inRow.length; ++i) {
            res[i] = inRow[inRow.length - 1 - i];
        }
        return res;
    }

    private static void checkInput(final int[][] matrix) {
        // Check if all rows have the same number of columns
        for (int i = 1; i < matrix.length; i++) {
            if (matrix[i].length != matrix[0].length) {
                throw new IllegalArgumentException("The input is not a matrix.");
            }
        }
    }
}