Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in Java Two words are anagrams if they contain the same letters in the same frequency. For instance, stale and least are anagrams of

Write in Java

Two words are anagrams if they contain the same letters in the same frequency. For instance, stale and least are anagrams of each other. A simple way to check this is to sort the characters in each word; if they get the same answer(in the example, we get aelst), the words are anagrams of each other. Write a Java method that uses the file dictionary.txt as the input and displays each word that is an anagram of each other in a group together.

Is there a way that i can have the words be read as input faster because it is taking a very long time for it to read in all the words from the dictionary.txt file. I have posted my java code below. If i could get help to have this read the input faster i would apprciate it. I have a very long list of words so if i could get it to read faster i would apprciate it

Code:

import java.io.File; import java.util.Arrays; import java.util.Scanner; public class Anagram { public static void main(String[] args)throws Exception { String filename = "/Users/blakethomas/Downloads/dictionary.txt"; System.out.println("The anagrams in group are as follows..."); anagramPrint(filename); } public static void anagramPrint(String filename) throws Exception { File file = new File(filename); Scanner sc = new Scanner(file); /** *Creating array of string to store all the values in it * */ String words[] = new String[100000]; int index=0; while (sc.hasNextLine()) { words[index] = sc.nextLine(); index++; } for(int i=0;i                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

Why might operating losses increase after-tax borrowing cost?

Answered: 1 week ago