Results 1 to 4 of 4
  1. #1
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default Having problems reading expression with String tokenizer

    I figured out my problem! Thanks for the suggestions!
    Last edited by dragstang86; 06-29-2011 at 06:25 PM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    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.

  3. #3
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default

    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!

  4. #4
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default

    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!

Similar Threads

  1. Need help with string tokenizer
    By ShortIt in forum New To Java
    Replies: 1
    Last Post: 02-18-2011, 07:04 PM
  2. String Tokenizer help
    By GreenTea in forum New To Java
    Replies: 4
    Last Post: 10-30-2010, 02:44 AM
  3. String Tokenizer
    By hussainian in forum Advanced Java
    Replies: 1
    Last Post: 03-16-2010, 08:58 AM
  4. String Tokenizer
    By viperlasson in forum New To Java
    Replies: 1
    Last Post: 03-09-2010, 01:14 PM
  5. string tokenizer
    By twinytwo in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •