here i have a dictionary with the words and i have to find the words with...

90.2K

Verified Solution

Question

Programming

here i have a dictionary with the words and i have to find thewords with the largest size, (i mean word count for egabdominohysterectomy) which have anagrams , like for example ,loop-> pool. Also , i have to sort them in alphabetical way so whatcould be the algorithm for that

public class Anagrams {
   private static final int MAX_WORD_LENGTH = 25;
   private static IArray>theDictionaries =
       newArray<>(MAX_WORD_LENGTH);
   public static void main(String... args) {
       initTheDictionaies();
       process();
   }
   private static void process() {
//start here
       if (isAnagram(\"pool\", \"loop\")){                  // REMOVE
          System.out.println(\"ANAGRAM!\");                  //REMOVE

      
//above this
   }
  
   private static boolean isAnagram(String word1, Stringword2) {
       boolean b = false;
       if(getWordSorted(word1).equals(getWordSorted(word2))) {
           b = true;
       }
       return b;
   }
   private static String getWordSorted(String word){
       ISortedListsortedLetters = new SortedList<>();
       StringBuilder sb = newStringBuilder();
       for (int i = 0; i           sortedLetters.add(word.charAt(i));
       }
       for (Character c : sortedLetters){
          sb.append(c);
       }
       String sortedWord =sb.toString();
       return sortedWord;
   }
   private static void initTheDictionaies() {
       String s;
       for (int i = 0; i           theDictionaries.set(i, new Vector());
       }
       try (
           BufferedReaderbr = new BufferedReader(
              new FileReader(\"data/pocket.dic\")
           )
       ) {
           while ((s =br.readLine()) != null) {
             theDictionaries.get(s.length()).pushBack(s);
           }
       } catch (Exception ex) {
          ex.printStackTrace();
          System.exit(-1);
       }
       for (int i = 0; i           theDictionaries.get(i).shrinkToFit();
       }
   }
}

Answer & Explanation Solved by verified expert
3.8 Ratings (442 Votes)
process private static void process start here set the word size    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students