简体   繁体   English

2D数组通过Java中的不同行填充2D数组

[英]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). 我有方法将3(行和列)的2d数组转换为3+ 2的2d方法,即5(行和列)的2d数组。 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. 所以我需要用main方法中的w数组替换零。

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. 您需要调整索引,因为newArray在索引0处有额外的行和列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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