Computer Science Canada StringTokenizer problems |
Author: | Xi_is4COW [ Sun Feb 12, 2006 3:45 pm ] | ||
Post subject: | StringTokenizer problems | ||
I'm trying to load all of the words in a text file into a hashset...but it seems that the first letter is already deleted off automatically for some reason
|
Author: | McKenzie [ Sun Feb 12, 2006 8:07 pm ] | ||||
Post subject: | |||||
The line:
takes the first letter off. try:
OR make a custom method that uses read to read one word at a time. |
Author: | Xi_is4COW [ Sun Feb 12, 2006 8:11 pm ] |
Post subject: | |
whoa...i didnt know you noticed the post, well thanks for the help, i'll try that right away. |
Author: | Xi_is4COW [ Sun Feb 12, 2006 8:30 pm ] | ||
Post subject: | |||
Err....I tried the
thing but it seems like i dont know how to declare the line variable... |
Author: | Martin [ Sun Feb 12, 2006 8:44 pm ] | ||
Post subject: | |||
On the line above that, declare the variable line as a String.
|
Author: | wtd [ Sun Feb 12, 2006 8:46 pm ] |
Post subject: | |
Is there some reason the declaration has to be separate? |
Author: | Xi_is4COW [ Sun Feb 12, 2006 8:49 pm ] |
Post subject: | |
Martin wrote:
I tried that, but it just gave me an error that said that the left side "String" was not compatible with the right side "boolean" |
Author: | wtd [ Sun Feb 12, 2006 9:02 pm ] | ||||
Post subject: | |||||
Is being read as:
|
Author: | Xi_is4COW [ Sun Feb 12, 2006 9:17 pm ] | ||||
Post subject: | |||||
wtd wrote:
Is being read as:
So what exactly am I supposed to change in order to make it work? |
Author: | Martin [ Sun Feb 12, 2006 10:25 pm ] | ||||
Post subject: | |||||
The problem is the order of operations.
becomes:
Which evaluates to line = true or line = false. Think about it like this. If you wanted to evaluate 4+3 * 2 so that it gave you 7 * 2 = 14 (instead of 4 + 6 = 10), you would have to write it as (4+3)*2 So what you want to do is set line to wordfile.readLine(), and then check to see if line is null (just like in the above how we want to add 4 and 3, and then multiply the result by 2). How would you do this using brackets? |
Author: | Xi_is4COW [ Sun Feb 12, 2006 10:40 pm ] |
Post subject: | |
Oh I see I see....it was only a misplacement of brackets that was messing me up.. Thanks alot to everyone who helped out ![]() |