【发布时间】:2015-05-09 16:55:57
【问题描述】:
我正在尝试查找单词中字母子集的字谜;例如,如果单词是“hello”,程序将检查整个单词,然后检查缺少 1 个字母的单词,以此类推。
这是我的代码,我不确定我做错了什么:
import java.util.*;
import java.io.*;
class Perm {
public static void main(String[] args) {
System.out.println(permutations("hello"));
}
public static String permutations(String word) {
String s = "";
for(int i=0; i<word.length(); i++) {
char ithChar = word.charAt(i);
String newWord = word.substring(0,i) + word.substring(i+1);
s = permutations(newWord);
}
return s;
}
}
【问题讨论】:
-
请参阅stackoverflow.com/questions/4240080/…,了解如何在 Java 中正确获取字符串的所有排列
标签: java string permutation subset anagram