isAnagram
Category: Arrays
Author: Benson Limketkai
Book Chapter: 7.2
Problem: isAnagram
Assume that the following method exists:
// returns the order number of each letter (case-insensitive)
public static int charToIndex(char letter)
For example:
+------------------+---------+
| Call | Returns |
+------------------+---------+
| charToIndex('a') | 1 |
+------------------+---------+
| charToIndex('A') | 1 |
+------------------+---------+
| charToIndex('e') | 5 |
+------------------+---------+
| charToIndex('Z') | 26 |
+------------------+---------+
Write a static method isAnagram that accepts two words as parameters and returns whether the words are anagrams of each other. An anagram of a word is another word that uses the exact same letters. For example, "asleep" and "please" are anagrams as are "dad" and "add".
+-------------------------------+---------+
| Call | Returns |
+-------------------------------+---------+
| isAnagram("asleep", "please") | true |
+-------------------------------+---------+
| isAnagram("dad", "add") | true |
+-------------------------------+---------+
| isAnagram("yes", " no") | false |
+-------------------------------+---------+
| isAnagram("yes", "yea") | false |
+-------------------------------+---------+
Hint: Tally letters