62,623
社区成员
发帖
与我相关
我的任务
分享 public static void main(String[] args) throws Exception {
boolean isExit = false;
BufferedReader bReader;
bReader = new BufferedReader(new InputStreamReader(System.in));
String str;
StringTokenizer sTokenizer;
ArrayList arrayList;
ArrayList result;
while (!isExit) {
str = bReader.readLine();
if (str.equalsIgnoreCase("exit")) {
isExit = true;
continue;
}
sTokenizer = new StringTokenizer(str, ",");
arrayList = new ArrayList();
while (sTokenizer.hasMoreTokens()) {
arrayList.add(sTokenizer.nextToken());
}
if (arrayList.size() <= 0) {
isExit = true;
continue;
}
result = new ArrayList();
for (int i = 0; i < arrayList.size(); i++) {
result = getCombination(result, (String) arrayList.get(i));
}
for (int j = 0; j < result.size(); j++)
System.out.print(result.get(j) + " ");
System.out.println();
}
}
public static ArrayList getCombination(ArrayList list, String str) {
ArrayList result = new ArrayList();
if (list == null || list.size() <= 0) {
for (int i = 0; i < str.length(); i++) {
result.add(str.substring(i, i + 1));
}
return result;
}
/* if (list.size() > str.length())
throw new IllegalArgumentException("传入参数无效!");*/
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < str.length(); j++) {
result.add(list.get(i) + str.substring(j, j + 1));
}
}
return result;
}