Write the Java code of the method Mirror that takes one 2-dimentional array (squared

matrix) A1, and returns 2D array A2 which is the mirror image of A1.

Sure! Here's the Java code for the `Mirror` method:

```java
public class Mirror {

public static int[][] getMirrorImage(int[][] matrix) {
int n = matrix.length;
int[][] mirror = new int[n][n];

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// Copy the element from the original matrix to the mirror matrix
mirror[i][j] = matrix[i][n - 1 - j];
}
}

return mirror;
}

public static void main(String[] args) {
int[][] matrix = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};

int[][] mirror = getMirrorImage(matrix);

// Print the original matrix
System.out.println("Original Matrix:");
printMatrix(matrix);

// Print the mirror matrix
System.out.println("Mirror Matrix:");
printMatrix(mirror);
}

public static void printMatrix(int[][] matrix) {
int n = matrix.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
System.out.println();
}
}
```

The `getMirrorImage` method takes a squared matrix `matrix` as input and returns the mirror image of the matrix as a new 2D array `mirror`.

To obtain the mirror image, we iterate through each element of the original matrix and copy it to the corresponding position in the mirror matrix. The corresponding position can be determined by using `n - 1 - j`, where `n` is the length of the matrix and `j` is the column index.

In the `main` method, we create a sample matrix and pass it to the `getMirrorImage` method. We then print both the original matrix and the mirror matrix using the `printMatrix` method. Finally, we define the `printMatrix` method to print the given matrix in a readable format.

You can run this code and check the output to see the original and mirror matrices.