Question
In this program, the user chooses the size of the row and column of the 2d array. Then they can pick a method they want
In this program, the user chooses the size of the row and column of the 2d array. Then they can pick a method they want to do to change the array. This method changes the size of the row and column and makes all the values 0. However it does not become the array they work with if they choose to do something with it, it will go back to the array that it was before changing the row and column and changing to 0. How do I get it to become the one the user works with?
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[newRow].length; newCol++) { matrix=newMatrix; } } for(int row=0; row< matrix.length; row++ ) { for(int column=0; column < matrix[row].length; column++) { matrix[row][column]=0; } } 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started