Solved

Java word pair freq counter program

Posted on 2012-04-09
2
639 Views
Last Modified: 2012-04-21
I have a program that I'm working on where I'm stuck on what to do next. I've got the java program to read and display a text file and what I need it to do after that is count the number of unique word PAIRS that appear in the text. I've attached the program I have put together along with the output that is desired. I also attached the text file that the program reads from to display the output.
I'd really like to know what coding I'll need to get the output, since I'm not really sure what way to go.
word1.txt
Output.txt
amazon.txt
0
Comment
Question by:teknogod02
2 Comments
 
LVL 11

Accepted Solution

by:
anilallewar earned 500 total points
ID: 37826763
The easiest way to do that would be to use a Java HashMap. You can create a java hasmap as below
HashMap<String, HashMap<String, Integer>> outerHashMap = new HashMap<HashMap<String, Integer>>();
HashMap<String, Integer> innerhashMap = new HashMap<String, Integer>();

So the algorithm would be something like this

Read next word from scanner
Check if word exists in outerHashmap; if not add a new innerhashmap.
If it exists, pick up the next word and check if it exists in the innerhashmap. If not, then add a new entry in the hashmap.
If the entry exists in inner hash map, then increment the value integer by 1.
0
 

Expert Comment

by:ratratratrat
ID: 37876915
ratratratrat
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 85
Core Java. What output will be and why ? 6 65
Oracle SQL syntax check  without executing 6 31
Not seen Link button 5 13
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now