这是我的代码。但它不起作用。请帮助我了解我的问题在哪里。这对我来说很复杂。我的代码必须发现我的 2 个输入是否是字谜。(例如:沉默和倾听)
import java.util.Scanner ;
import java.lang.String ;
public class Anagram {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in) ;
System.out.println("Enter your firs word: ");
String s1= scanner.nextLine() ;
System.out.println("Enter your second word: ");
String s2 = scanner.nextLine() ;
if(isAnagram(s1,s2)){
System.out.println("Your words are anagram") ;
}
}
public static boolean isAnagram(String s1, String s2) {
int a = s1.length() ;
int b= s2.length() ;
if (a==b){
int count=0;
int i,j ;
char x, y ;
for (i=0, j=0; i<=a; i++){
x = s1.charAt(i) ;
y = s2.charAt(j);
j++;
if (x==y){
count++ ;
while (count==a){
return true;
}
return false;
}
}
}
}
}