我有 6 个数组,每个数组有 8 个元素。我想编写一个方法来揭示所有数组的所有元素的所有可能组合,例如:
firstArray firstElement, secondArray firstElement,.... sixthArray firstElement
firstArray secondElement, secondArray firstElement,.... sixthArray firstElement
....etc...
firstArray lastElement, secondArray lastElement,.... sixthArray lastElement
我怎样才能以最有效、对性能最友好的方式做到这一点?
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < B.length; j++) {
for (int h = 0; h < C.length; h++) {
for (int k = 0; k < D.length; k++) {
for (int l = 0; l < E.length; l++) {
for (int n = 0; n < F.length; n++) {
System.out.println(A[i] + " "
+ B[j] + " "
+ C[h] + " "
+ D[k] + " "
+ E[l] + " "
+ F[n]);
}
}
}
}
}
}