import java.util.Scanner; /** * MakeAnagram */ public class MakeAnagram { // Anagran is 2 words compose of the sames letters such LISTEN and SILENT, MUG // and GUM, RATE and TEAR etc... public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter the first String here: " + "\t"); String str1 = sc.nextLine(); System.out.print("Please enter the second String here: " + "\t"); String str2 = sc.nextLine(); sc.close(); System.out.println(DeletionCount(str1, str2)); } private static int DeletionCount(String strOne, String strTwo) { int deletionCount = 0; int[] Freqency = new int[26]; strOne = strOne.toLowerCase(); strTwo = strTwo.toLowerCase(); // fill the frequency for strOne chars for (int i = 0; i < strOne.length(); i++) { Freqency[strOne.charAt(i) - 'a']++; } // fill the frequency for strTwo chars for (int i = 0; i < strTwo.length(); i++) { Freqency[strTwo.charAt(i) - 'a']--; } // to calculate the deletion count we are going to do the absolute addition of // the strOne and strTwo for (int x : Freqency) { deletionCount += Math.abs(x); } return deletionCount; } }