2

嗨伙计们,我有这样的事情:

  String keyBase = "keyA";
  String[] valueBase = {"a1","a2","a3"};

  String keyLevel1 = "keyB";
  String[] valueLevel1 = {"b1","b2","b3"};

  String keyLevel2 = "keyC";
  String[] valueLevel2 = {"c1","c2","c3"};

并且需要这样的东西:

String[][] f1 = {{"keyA","a1"},{"keyB","b1"}{"keyC","c1"}}
String[][] f2 = {{"keyA","a1"},{"keyB","b1"}{"keyC","c2"}}
String[][] f2 = {{"keyA","a1"},{"keyB","b1"}{"keyC","c3"}}

String[][] f5 = {{"keyA","a1"},{"keyB","b2"}{"keyC","c1"}}
String[][] f6 = {{"keyA","a1"},{"keyB","b2"}{"keyC","c2"}}
...

有什么简单但很好的方法来做到这一点?

谢谢

4

1 回答 1

0

我不知道递归排列。
我只是根据您的输出进行了尝试。

for(int i = 0 ; i <3 ; i++) {
   for(int j = 0 ; j <3 ; j++) {
      for(int k = 0 ; k <3 ; k++) {
         system.out.println(keyBase +","+ valueBase[i] +","+
                            keyLevel1  +","+ valueLevel1[j]  +","+
                            keyLevel2  +","+ valueLevel2[k] )
      }
   }
 }
于 2013-02-08T05:31:12.690 回答