填充二维数组在Java 2维数组 [英] populating 2d array with two 1d arrays in java
本文介绍了填充二维数组在Java 2维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2维数组和IM尝试将它们填充到JAVA一个二维数组。
I have 2 1d arrays and im trying to populate them into a single 2d array in JAVA.
例如:
x[] = {2,5,7,9}
y[] = {11,22,33,44}
结果应该然后就:
The results should then be:
result[][] = {{2,5,7,9}, {11,22,33,44}}
我怎么去呢?我现在有这样的事情:
How do I go about this? I currently have something like this:
for(int row = 0; row < 2; row++) {
for(int col = 0; col == y.length; col++) {
???
}
}
林之类的卡在那里...
Im sort of stuck from there...
推荐答案
二维数组是数组的数组。那么,为什么不试试呢?
2D array is an array of arrays. So why don't you try this?
int result[][] = {x,y};
和确保它是如此简单和工程,测试:
And to make sure that it is so simple and works, test this:
for(int i=0; i<result.length; i++)
{
for(int j=0; j<result[0].length; j++)
System.out.print(result[i][j]+ " ");
System.out.println();
}
这篇关于填充二维数组在Java 2维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文