1

例如,我正在制作一个刽子手程序,并且对于我想要创建一个数组words的单词,单词中的项目是字母什么单词

这就是我认为你可以做的:

String[] words =  new String [15];
words[1] = String[] MILK = {"M","I","L","K"};
words[2] = String[] CLOTH = {"C","L","O","T","H"};
4

4 回答 4

6

您可以使用数组数组

String[][] arrays = new String[][] { array1, array2,  array53};
于 2013-06-06T18:35:08.957 回答
3

你想要的是一个多维数组。这些基本上是数组内部的数组。

您的代码应如下所示:

String[][] words =  new String [15][];
words[1] = new String[] {"M","I","L","K"};
words[2] = new String[] {"C","L","O","T","H"};

有关它的文档,请参阅此网站

于 2013-06-06T18:37:07.497 回答
3

我认为您正在寻找:

String[][] words =  new String [15][];
String[] milk = words[0] = new String[] {"M","I","L","K"};
String[] cloth = words[1] = new String[] {"C","L","O","T","H"};
于 2013-06-06T18:38:39.573 回答
1

您将使用的是一个二维数组。

把它想象成一个看起来像这样的矩阵

[][][][]
[][][][]
[][][][]
[][][][]

每个盒子都包含一个字母。

您使用以下代码进行初始化

String[][] words =  new String [x][y];

其中 x 是单词(行)的总数,y 是字母(列)的总数。

于 2013-06-06T19:07:59.127 回答