Solved

Java word pair freq counter program

Posted on 2012-04-09
2
632 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

12 Experts available now in Live!

Get 1:1 Help Now