Solved

Java word pair freq counter program

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

695 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