# problem StreamTokenizer??

raghav shukla
Greenhorn
Posts: 2
i wish to design a class as a tool for solving polynomial equations.

user interaction:
user enters the data through the keyboard. the program finds the roots of the equation and displays the results.

the program is divided into two significant processes.
1. scanning the equation for corect format
2. finding the roots.

its just to practice streamtokenizers

the user would enter the equation as

12x^2+3x^1+5=0

the program would scan the equation and extract the relevent coefficients and use them in the formula to generate results. for this i need to create a mapping of coefficient with respect to specific power of x.

THE PROBLEM:

tokens generated would be

12
x^2
3
x^1
5

it considers x^2 as a token. how do i extract power 2 from here. if i extract single character then coefficient 12 will be taken as
1 (first token)
2 (another token)
something that i dont want.

how to specify delimiter in StremTokenizers.how to look for a specific delimiter. i know this can be dont using utilities like java.util.scanners but i just wish to use StreamTokenizer class.

Nitesh Kant
Bartender
Posts: 1638
raghav: tokens generated would be

12
x^2
3
x^1
5

Why do you say that these will be the generated tokens? Have you tried it?
For the given equation, the tokens will be:
12
x
^
2
+
3
x
^
1
+
5
=
0

In the above case,
• if the token is a number then its value can be retrieved from the field: nval of StreamTokenizer
• if the token is a string then its value can be retrieved from the field: sval of StreamTokenizer
• if the token is any other character then its value can be retrieved from the field: ttype of StreamTokenizer

• I think given the above tokens, you can easily get the logic to get the required data.

raghav: how to specify delimiter in StremTokenizers.how to look for a specific delimiter.

You dont have to specify delimiters in a StreamTokenizer.