Hello all,
I have a slight issue with the String Tokenizer class. Here's what I have, I'm parsing a text file like so:
10 9 7
6 8 9
11 4 13
A few rows of 3 numbers each. I have the string tokenizer running and it picks up the first two numbers in each row but I always get a zero for the last numbers. Here's a snippet of my code:
As you can see, I have a while loop with a switch statement inside, then within each of the cases (there are 3) there is another nested while loop with another switch statement inside. Hence the larger while loop/switch statement combo looks at the lines while the nested while loop/switch statement combos get the individual tokens within each line and turn them into numbers. Those numbers are then stored in variables in another class. Does anyone have any idea what's going on? I just can't seem to get that last set of numbers.
Thanks,
Jisoo22
I have a slight issue with the String Tokenizer class. Here's what I have, I'm parsing a text file like so:
10 9 7
6 8 9
11 4 13
A few rows of 3 numbers each. I have the string tokenizer running and it picks up the first two numbers in each row but I always get a zero for the last numbers. Here's a snippet of my code:
Code:
while(line != null)
{
tokenizer = new StringTokenizer(line);
token = tokenizer.nextToken();
switch(lineNum)
{
// parses for first line
case 1:
casenum = 0;
while(tokenizer.hasMoreTokens())
{
switch(casenum)
{
// parses for first number
case 0:
temp = Integer.parseInt(token);
fl.setCompact(temp);
casenum++;
break;
case 1:
temp = Integer.parseInt(token);
fl.setMid(temp);
casenum++;
break;
case 2:
temp = Integer.parseInt(token);
fl.setVan(temp);
casenum++;
break;
}
token = tokenizer.nextToken();
}
break;
As you can see, I have a while loop with a switch statement inside, then within each of the cases (there are 3) there is another nested while loop with another switch statement inside. Hence the larger while loop/switch statement combo looks at the lines while the nested while loop/switch statement combos get the individual tokens within each line and turn them into numbers. Those numbers are then stored in variables in another class. Does anyone have any idea what's going on? I just can't seem to get that last set of numbers.
Thanks,
Jisoo22