Solved

Java word pair freq counter program

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse buid path vs tomcat lib path 10 34
how to debug htl and js pages 8 39
hashmap order 17 37
java mysql insert application 14 29
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

820 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