Write the program described below.

Show answer
Answer
import java.util.Scanner;
class MatRev
{
int arr[][];
int m, n;
MatRev(int mm, int nn)
{
m = mm;
n = nn;
arr = new int[m][n];
}
void fillarray()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter " + (m * n) + " elements:");
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
arr[i][j] = sc.nextInt();
}
int reverse(int x)
{
int rev = 0;
while (x != 0)
{
rev = rev * 10 + x % 10;
x = x / 10;
}
return rev;
}
void revMat(MatRev P)
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
arr[i][j] = reverse(P.arr[i][j]);
}
void show()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
System.out.print(arr[i][j] + "\t");
System.out.println();
}
}
public static void main(String args[])
{
MatRev A = new MatRev(3, 3);
A.fillarray();
MatRev B = new MatRev(3, 3);
B.revMat(A);
System.out.println("Original matrix:");
A.show();
System.out.println("Reversed matrix:");
B.show();
}
}Explanation: reverse(x) reverses the digits of a single integer x using the standard while-loop technique. revMat(P) takes another MatRev object P as a parameter, and for every cell (i,j) stores in the current object's arr the reverse of P's corresponding element, leaving P itself unchanged. Tested (run for real) with the example matrix {{72,371,5},{12,6,426},{5,123,94}}: the program correctly produced the reversed matrix {{27,173,5},{21,6,624},{5,321,49}}, matching the example exactly.