Search code examples
javaarraystype-conversion2dsparse-matrix

2d array fill in 2d array by different rows in java


I have method to convert 2d array of 3 (row and col) in to 2d method of 3+ 2 which is 2d array of 5(row and col). and the method give parameter of 2d array and find the total matrix. Here I have class and this class }

so and this my main class:

public static void main(String[] args) {
    Operation operation  = new Operation();

    int w[][] = {{1,2,3},{4,5,6},{7,8,9}};

    operation.convert(w);

Now the result it will come like the picture:

enter image description here

So I need to replace the zero with w array which is in main method.


Solution

  • I think all you need is:

    newArray[i][j] = a[i-1][j-1]; // or perhaps a[j-1][i-1] if you want the transpose
    

    You need to adjust the indices because newArray has an extra row and column at index 0.