@@ -0,0 +1,1463 @@
+package java_problems.strings;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement%0D%0A * %0D%0A * Two strings A and B are called anagrams if they consist same characters, but%0D%0A * may be in different orders. So the list of anagrams of CAT are %22CAT%22, %22ACT%22 ,%0D%0A * %22TAC%22, %22TCA%22 ,%22ATC%22 and %22CTA.%0D%0A * %0D%0A * Given two strings, print %22Anagrams%22 if they are anagrams, print%0D%0A * %22Not Anagrams%22 if they are not. The strings may consist at most 50 english%0D%0A * characters, the comparison should NOT be case sensitive.%0D%0A * %0D%0A * This exercise will verify that you are able to sort the characters of a%0D%0A * string, or compare frequencies of characters.%0D%0A * %0D%0A * Sample Input:%0D%0A * anagram%0D%0A * margana%0D%0A * %0D%0A * Sample Output:%0D%0A * Anagrams%0D%0A */%0D%0Apublic class Anagrams %7B%0D%0A%0D%0A%09static boolean isAnagram(String A, String B) %7B%0D%0A%09%09A = A.toLowerCase();%0D%0A%09%09B = B.toLowerCase();%0D%0A%0D%0A%09%09if (A.length() != B.length()) %7B%0D%0A%09%09%09return false;%0D%0A%09%09%7D%0D%0A%09%09char%5B%5D charsInA = A.toCharArray();%0D%0A%09%09char%5B%5D charsInB = B.toCharArray();%0D%0A%09%09Arrays.sort(charsInA);%0D%0A%09%09Arrays.sort(charsInB);%0D%0A%09%09for (int i = 0; i %3C charsInA.length; i++) %7B%0D%0A%09%09%09if (charsInA%5Bi%5D != charsInB%5Bi%5D) %7B%0D%0A%09%09%09%09return false;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return true;%0D%0A%09%7D%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%0D%0A%09%09Scanner sc = new Scanner(System.in);%0D%0A%09%09String A = sc.next();%0D%0A%09%09String B = sc.next();%0D%0A%09%09boolean ret = isAnagram(A, B);%0D%0A%09%09if (ret) %7B%0D%0A%09%09%09System.out.println(%22Anagrams%22);%0D%0A%09%09%7D else %7B%0D%0A%09%09%09System.out.println(%22Not Anagrams%22);%0D%0A%09%09%7D%0D%0A%09%09sc.close();%0D%0A%09%7D%0D%0A%7D

Add Anagrams