Possible Duplicate:
Anagram algorithm in java
public static boolean test(String a, String b) {
a=a.toLowerCase();
b=b.toLowerCase();
boolean result = true ;
boolean tmp1=false;
if(a.length()==b.length()){
for(int i=0;i<a.length();i++){
tmp1=false;
for(int k=0;k<b.length();k++){
if(a.charAt(i)==b.charAt(k)){
return true;
}
}
if(tmp1==false){
result=false;
break;
}
if(i==a.length()-1)
result=true;
}
}
else {
result=false;
}
return result;
}
I want to make a program to find anagram words.
The code works correctly when the input is
- word one is dsa
- second word is asd
- The output is anagram (correct result)
The code fails for the input
- first word is assa
- second word is asaa
- result is anagram (INCORRECT result)
What is my fault?