public static int[][] submatrix(int[][] arr, int i, int j)
{
    int[][] copyArr = arr;
    int[][] newArr = new int[copyArr.length - 1][copyArr[0].length - 1];
    
    for(int k = 0; k < copyArr[0].length; k++)
    {
        copyArr[j - 1][k] = 0;
    }
    
    for(int x = 0; x < copyArr.length; x++)
    {
        copyArr[x][i - 1] = 0;
    }
    printMatrix(copyArr);
    System.out.println();
    int row = 0;
    int col = 0;
    
    for(int x = 0; x < copyArr.length; x++)
    {
        for(int y = 0; y < copyArr[0].length; y++)
        {
            if(copyArr[x][y] != 0)
            {
                newArr[row][col] = copyArr[x][y];
                col += 1;
                if(col == newArr[0].length)
                {
                    col -= newArr[0].length;
                    row += 1;
                }
            }
        }
    }
    return newArr;
}
When I run this and use the 2d array:
int[][] matrixI = new int[][]{{11, 12, 13, 14}, {21, 22, 23, 24}, {31, 32, 33, 34}, {41, 42, 43, 44}};
It correctly calculates the sub matrix, but when I call the method again on the same 2d array with different parameters(for the row and column I am getting rid of) it uses the array that was made when I called it the first time. I tried to use a copy of the array to avoid it changing the value of the inputted arr but it is still changing it.
The program is changing my value of arr when I dont want it to.
 
     
    