You are viewing a single comment's thread. Return to all comments →
Hello! I put here my solution! I know maybe it's not the best solution but with I'm open to opinions! :)
import java.util.Scanner;
public class Solution {
static boolean isAnagram(String a, String b) { boolean check; String a1 = a.toLowerCase(); String b2 = b.toLowerCase(); char[] sortA1 = a1.toCharArray(); char[] sortB2 = b2.toCharArray(); java.util.Arrays.sort(sortA1); java.util.Arrays.sort(sortB2); a1 = new String(sortA1); b2 = new String(sortB2); if (a1.equals(b2) ) { check = true; } else { check = false; } return check; } 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" ); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Anagrams
You are viewing a single comment's thread. Return to all comments →
Hello! I put here my solution! I know maybe it's not the best solution but with I'm open to opinions! :)
import java.util.Scanner;
public class Solution {
}