Simple java solution
\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n        int n=mat[0].length;\n        if(r*c!=mat.length*n) {\n            return mat;\n        }\n
```\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n        int n=mat[0].length;\n        if(r*c!=mat.length*n) {\n            return mat;\n        }\n        int[][] ans = new int[r][c];\n        for(int i=0;i<r*c;i++) {\n            ans[i/c][i%c]=mat[i/n][i%n];\n        }\n        return ans;\n    }\n```
['Java']