ПЕРВИЧНЫЙ ВОПРОС
Вам необходимо иметь "возврат" вне операторов if.
else if(arr1.equals(arr2))
{
System.out.println("Anagrams");
return true;
}
return false; //add this here. I tested, error goes after this.
}
Проверено здесь - https://onlinegdb.com/S188-FdGL
ДОПОЛНИТЕЛЬНО
Ваш лог Anagram c неверен.
Правильный лог c должен быть таким (следуйте комментариям, чтобы понять).
import java.util.Scanner;
import java.util.Arrays;
public class Solution {
static boolean isAnagram(String a, String b)
{
char[] arr1 = a.toLowerCase().toCharArray();
char[] arr2 = b.toLowerCase().toCharArray();
int n1 = arr1.length;
int n2 = arr2.length;
// If length is different, then they cannot be Anagram
if (n1 != n2) return false;
// Sort the Character Arrays
Arrays.sort(arr1);
Arrays.sort(arr2);
// Compare each characters of sorted Character Arrays,
// if any character mismatches, it is not an Anagram
for (int i = 0; i < n1; i++)
if (arr1[i] != arr2[i])
return false;
// If all characters of both character Arrays are same,
// only then, the String are Anagrams, so return true
return true;
// Also, remove the print statements from this method,
// as you are already printing in the main method,
// so it creates duplicate prints
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a = scan.next();
String b = scan.next();
scan.close();
boolean ret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}
Проверено здесь - https://onlinegdb.com/rJe-OEtuGL