Results 1 to 2 of 2
- 02-19-2012, 08:14 PM #1Member
- Join Date
- Apr 2011
- Rep Power
Counting the fequency of word combinations
So Ive been working on this program which would take a sentence, create all possible word combinations and then record how many times that combination occurred. So far Ive been able to generate the word combinations with a 2d array. ex:
combinations   
W1 W1 1
W1 W2 1
W1 W3 1
... ... .
Wn Wn 1
Where the first two column are the combination and the frequency is an int in the third column. Right now I have my first two columns done but how would I go about adding that frequency to the combination?
I suppose I have a few questions:
1)Can I have one of the columns to an int (is that possible), if so how would I declare that/go about doing that?
2)Is there a better way to count the amount of times that a combination appears?
Thanks in advance.
- 02-19-2012, 09:59 PM #2
Re: Counting the fequency of word combinations
You can not mix data types in an array.
If you know about how to create classes, this would be a place you could use a class with the three variables: 2 String and 1 int.
You'd create the object, store the values in it and save the object in an ArrayList.
Otherwise you will need another parallel array to hold the int counts.
- By Roam in forum New To JavaReplies: 12Last Post: 08-25-2011, 10:22 PM
- By KAS in forum New To JavaReplies: 15Last Post: 05-16-2011, 06:47 PM
- By noobinoo in forum New To JavaReplies: 4Last Post: 05-07-2010, 02:06 PM
- By jaq in forum New To JavaReplies: 2Last Post: 12-02-2009, 07:12 PM
- By Alistair in forum New To JavaReplies: 2Last Post: 05-15-2008, 03:48 AM