Question: I'm trying to take the original 2d array ( one where the user enters the number of rows and columns and then it gets filled
I'm trying to take the original 2d array ( one where the user enters the number of rows and columns and then it gets filled with random numbers) and change the row and columns in it by pointing the reference variable. Then after that, I need to reinitialize all the values in the array to 0.
//here's the part of my program when I try to make the new 2d array
public static int[][] newArray(int[][] matrix) { int[][]newMatrix= new int[4][5]; for(int newRow=0; newRow < newMatrix.length; newRow++) { for(int newCol=0; newCol < newMatrix[0].length; newCol++) { newMatrix[newRow][newCol]=matrix[newRow][newCol]; } } for(int row=0; row < matrix.length; row++) { for(int column = 0; column < matrix[row].length; column++) { System.out.print(matrix[row][column]+" "); } System.out.println(); } return matrix; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
