I just would like to ask what is wrong regarding my code for it does not output that the 2 words are anagram. Appreciate any help thanks.
public class Program {
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;
}}