简体   繁体   中英

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:

在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM