例如,我正在制作一个刽子手程序,并且对于我想要创建一个数组words
的单词,单词中的项目是字母什么单词
这就是我认为你可以做的:
String[] words = new String [15];
words[1] = String[] MILK = {"M","I","L","K"};
words[2] = String[] CLOTH = {"C","L","O","T","H"};
您可以使用数组数组
String[][] arrays = new String[][] { array1, array2, array53};
你想要的是一个多维数组。这些基本上是数组内部的数组。
您的代码应如下所示:
String[][] words = new String [15][];
words[1] = new String[] {"M","I","L","K"};
words[2] = new String[] {"C","L","O","T","H"};
有关它的文档,请参阅此网站
我认为您正在寻找:
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"};
您将使用的是一个二维数组。
把它想象成一个看起来像这样的矩阵
[][][][]
[][][][]
[][][][]
[][][][]
每个盒子都包含一个字母。
您使用以下代码进行初始化
String[][] words = new String [x][y];
其中 x 是单词(行)的总数,y 是字母(列)的总数。