Results 1 to 2 of 2
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    63
    Rep Power
    0

    Default 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 [0] [1] [2]
    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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default 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.

Similar Threads

  1. Combinations in Java
    By Roam in forum New To Java
    Replies: 12
    Last Post: 08-25-2011, 10:22 PM
  2. Counting occurence of a word in file
    By KAS in forum New To Java
    Replies: 15
    Last Post: 05-16-2011, 06:47 PM
  3. Replies: 4
    Last Post: 05-07-2010, 02:06 PM
  4. Counting specific word from a file
    By jaq in forum New To Java
    Replies: 2
    Last Post: 12-02-2009, 06:12 PM
  5. [SOLVED] Help on Word and Character counting in java
    By Alistair in forum New To Java
    Replies: 2
    Last Post: 05-15-2008, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •