[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Java word pair freq counter program

Posted on 2012-04-09
2
Medium Priority
?
662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
anilallewar earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This video teaches viewers about errors in exception handling.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

649 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