赞
踩
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
public class GetAssemble {
public static Set set = new TreeSet();
public static void doSet(String start, String[] sourceList, int max) {
String[] olds = start.split("_");
if (olds.length == max) {
set.add(start.replaceAll("_", "").trim());
}
else {
for (int s = 0; s
if (Arrays.asList(olds).contains(sourceList[s])) {
continue;
}
else {
doSet(start + "_" + sourceList[s], sourceList, max);
}
}
}
}
public static void doSet(String[] sourceList, int max) {
for (int start = 0; start
doSet(sourceList[start], sourceList, max);
}
}
public static void print() {
System.out.println("Total:" + set.size());
int cols = 10;
for (String s : set) {
System.out.print(s + " ");
if (cols-- == 1) {
System.out.println();
cols = 10;
}
}
set.clear();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] haha = new String[] { "1", "2", "3", "4", "5" };
System.out.println();
System.out.println(" ");
doSet(haha, 5);
print();
}
}
解析看不懂?求助智能家教解答查看解答
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。