Trying to figure out why code wont work. Its gets 2 errors for
String newS1 = s1.sort;
String newS2 = s2.sort;
I dont know how know whats wrong
public class anagram {
public static void main(String args[]) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter the first string: ");
String first = input.nextLine();
System.out.print("Enter the second string: ");
String second = input.nextLine();
System.out.println(
first + " and " + second + " is " +
(isAnagram(first, second) ? "anagram." : "not anagram."));
}
public static boolean isAnagram(String s1, String s2) {
String newS1 = s1.sort;
String newS2 = s2.sort;
if (newS1.length() != newS2.length()) return false;
for (int i = 0; i < newS1.length(); i++) {
if (newS1.charAt(i) != newS2.charAt(i))
return false;
}
return true;
}
}