I am using a scanner to read in some expression like (add 3 4) and (mul 2 3). Now I am suppose to be able to read expressions like (add 3(mul 2 3)) and it work. But it keeps on throwing an error. When I debug the program I can tell that the scanner is reading the second paren and then it reads something else in so therfore I get a message saying that about my number formatting say 3mul is not valid. Here is my code it is quite long sorry. Any help would be great.
I would usually try to get the code to compile successfully, before trying to debug it. You seem to have omitted a few things here. Additionally, if you could provide a simple main() method that uses the class in a way that demonstrates the error you're talking about, that would be helpful. Or failing that, show us the error you get (with stack trace), and see what exactly is at the line numbers which are referenced in the stack trace. That will probably be more helpful that letting us look at the code from scratch and trying to guess what you're doing.
"I'm not back." - Bill Harding, Twister
Joined: Feb 03, 2006
I'm sorry about that. I forgot the import statement.
and here is the main method
Here is the errors I get
Joined: Jan 30, 2000
One of your methods is still missing a return statement. And your stack trace refers to a parseInt() method which does not exist anywhere in the code you've shown. I would recommend editing the original post and replacing all the code at once with the correct code, rather than bringing in bits and pieces that don't quite fit together.
I would guess that, if you've got a Scanner, there's no need for Integer.parseInt() - you can check for a number with hasNextInt(), and get the number with nextInt(). And this has the advantage of just grabbing the numeric part of the input, and stopping at the first non-numeric input (e.g. "mul".) So then you can parse that next non-numeric bit with another method. It looks like you're tryign to use Integer.parseInt() to parse too much at once ("3mul"), and it's choking on the non-numeric part.
Joined: Feb 03, 2006
okay I am sorry for the missing code. I had a lot of commented out code that I deleted before posting it and I must have accidently deleted some of the good code. Here is the code all of it.