![]() |
|
#1
|
|||
|
|||
Java DifficultyHey Folks,
Ive hit a bit of a stumbling block and i cant seem to get past it. For the last while now i have been trying to count the number of words with the same number of letters in the words from a text file (test.txt). For example an out put would be.... "There are 5 words with 1 letter." "There are 15 words with 2 letters" "There are 45 words with 3 letters" and so on and so forth.I have imagined that it should be done with arrays. One for the number of letters in that word and one for the count of its occurance but so far i have no luck in getting the count to match the letters of the word, but have been able to count all words in the txt file. Also currently can figure out how to sort an array to out put the 20 most common words. Both these cases would need to print words to a different txt file (results.txt) Some of the code that i have tried so far..................... Any help is greatly welcomed...been banging my head for too long on this now.... Regards, Richielit JAVA Code:
Last edited by admin II : 07-May-2008 at 04:16.
Reason: Please surround your Java code with [java] your code [/java]
|
|
#2
|
|||
|
|||
Re: Java DifficultyOnce you have read all of your words in to your list, you could create a map.
JAVA Code:
See this tutorial for more info. |
|
#3
|
|||
|
|||
Re: Java DifficultyI would make a linked list, and insert the words as nodes based on their length. That way you could just take the top 20 words that have the most inserts.
and also you could have more than just the number of characters in the node if you wanted more information stored.. Justin Fox |
|
#4
|
|||
|
|||
Re: Java DifficultyHere is a simple example of a DLL that I wrote up, suprisingly it worked perfect lol.
JAVA Code:
you could always write a method that will insert after a number, or even better, insert before a node which number of characters is greater than the one to insert, and if you reach then end, then let head.prev.next = newnode and newnode.next = head hope this atleast sounds interesting, Justin Fox |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C code to Java | bengt23648 | Java Forum | 2 | 09-Sep-2007 05:33 |
| What is the equivalent in Java for a Function or Module in VB | pengwinz | Java Forum | 2 | 17-May-2007 20:02 |
| To post messages / click Buttons of a Java Jar App using code | Jun0 | C Programming Language | 1 | 06-Jan-2007 14:44 |
| To post messages / click Buttons of a Java Jar App using code | Jun0 | Java Forum | 0 | 06-Jan-2007 11:14 |
| Scalability in Java and C++ | agx | Miscellaneous Programming Forum | 7 | 04-Feb-2006 15:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The