【发布时间】:2015-10-28 19:29:21
【问题描述】:
我只是想问一下我的代码有什么问题,因为它没有输出这两个单词是字谜。感谢任何帮助,谢谢。
公开课程序{
public static void main(String[] args){
String word1 ="test";
String word2 = "tset";
boolean output = isAnagram(word1,word2);
System.out.println("isAnagram:"+output);
}
public static boolean isAnagram(String word1, String word2){
boolean output = false;
boolean found = false;
int x = 0;
int ctr = 0;
for(int i=0; i<word1.length()-1;i++){
x=0;
found=false;
while(found!=true){
if(word1.charAt(x)==word2.charAt(i)){
ctr++;
found=true;
}
else{
x++;
}
}}
if(ctr==word1.length()&&ctr==word2.length()){
output = true;
}
return output;
}}
【问题讨论】:
-
Anagram algorithm in java 的可能重复项
-
我们不是来猜测您的代码可能有什么问题,特别是如果您懒得解释它是如何工作不正常的。
标签: java