如何从一个阵列添加到字符串Java中的另一个数组 [英] How to add strings from one array into another array in Java
问题描述
我有一个字符串名为initStrings数组,并呼吁广场的数组。我需要从initStrings采取字符串和一个将它们添加一成不同的行数组广场
I have an array of strings called initStrings and an array called squares. I need to take the strings from initStrings and add them one by one into different rows in the array squares
static String[] initStrings =
{
"...../...\\",
"..\\.......",
"......./..",
"..........",
"........\\.",
"..........",
"..........",
".....\\../.",
"..\\....../",
".........."
};
static int [][] squares;
public static void initialize()
{
int [][] squares = new int [10][10];
for (col = 0; col < 10; col++)
{
for (rows = 0; rows < 10; rows ++)
{
squares[col][rows] = initStrings();
}
}
有人告诉我,在课堂上,我需要一个嵌套循环要做到这一点,但行循环内我想不出放什么。任何帮助吗?
I was told in class that I need a nested for loop to do this but inside the rows loop I can't figure out what to put. Any help?
推荐答案
这是一个有点迷惑你想达到什么样的,但回答你的问题是,你需要另一个循环的initStrings阵列上运行(这你作为函数调用。同时它是一个1维数组,所以你需要了解你想放的平方阵列也就是2维)
it's a little bit confusing what you're trying to achieve, but the answer to your question is that you need another loop to run on the initStrings array (which you called as a function. also it's a 1 dimension array so you need to understand what you want to put inside the squares array which is 2 dimensions)
希望这有助于
这篇关于如何从一个阵列添加到字符串Java中的另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!