I figured out my problem! Thanks for the suggestions!
Printable View
I figured out my problem! Thanks for the suggestions!
About the only way you can parse this is to read it one character at a time into a StringBuilder. For example if you had 24+78 you would read the 2 and store it. Then read the 4 and store it with the 2. Then read the +, now you know you have reached the end of the digit and you can call parseInt and do whatever else needs to be done.
Ok I see what you mean. I guess I will go ahead and get it working properly with spaces first. Right now it is only reading in the first complex number correctly and with the debugging statements the output I get is:
Enter a postfix expression of complex numbers (Ex: ( 2 + 3 i ) ( 1 + 10 i ) + ):
( 2 + 3 i ) ( 1 + 10 i ) +
13
charConv = (
nextChar = (
Inside Complex(), real = 2.0, oper = +, imag 3.0
charConv = ( 1 + 10 i
nextChar =
charConv = +
nextChar =
The result of your input is:(2.0 + 3.0i)
Evaluate another expression? (Y = Yes):
I can't figure out why it is seeing the second complex number as one token? I dont know what is happening to the last parenthesis either. The countTokens() method is displaying 13 which is correct. I have been trying to figure this problem out for hours!
I have figured out the problem starts when I declare the tokenizer in the main
"StringTokenizer expression = new StringTokenizer(input.nextToken(")"));"
Before that point I can iterate through the string with nextToken(). After I pass the tokenizer to fromString(), and it works correctly but after returning to the main the expression is being seen as just one token. Im sure the problem is siimple but I have been trying to figure out for hours and hours now! Please help!