static void generator7(String fileName) throws IOException {
FileWriter fw = new FileWriter(fileName);
String[] list = { "a", "b", "c", "d" };
for (int o = 0; o < list.length; o++) {
for (int n = 0; n < list.length; n++) {
for (int m = 0; m < list.length; m++) {
for (int l = 0; l < list.length; l++) {
for (int k = 0; k < list.length; k++) {
for (int j = 0; j < list.length; j++) {
for (int i = 0; i < list.length; i++) {
fw.append(list[i] + list[j] + list[k]
+ list[l] + list[m] + list[n]
+ list[o]);
fw.append("\n");
}
}
}
}
}
}
}
}
我有这段代码用来生成不同的字母组合(a、b、c、d)。我希望它能够生成 aaaaaaa、aaaaaac、aaaaaaag、aaaaaaat 到 tttttt。然而,产生的组合在 tttttgt 处停止。没有异常抛出。我不知道我的代码的哪一部分出错了。请帮忙。
static void generator7(String fileName) throws IOException {
FileWriter fw = new FileWriter(fileName);
String[] list = { "a", "b", "c", "d" };
for (int o = 0; o < list.length; o++) {
for (int n = 0; n < list.length; n++) {
for (int m = 0; m < list.length; m++) {
for (int l = 0; l < list.length; l++) {
for (int k = 0; k < list.length; k++) {
for (int j = 0; j < list.length; j++) {
for (int i = 0; i < list.length; i++) {
fw.append(list[i] + list[j] + list[k]
+ list[l] + list[m] + list[n]
+ list[o]);
fw.append("\n");
}
}
}
}
}
}
}
fw.flush();
fw.close();
}
编辑:第一个代码是问题所在。第二个代码是解决方案。