Hi,
I am working on a sort of stack calculator. If anyone can suggest a better method please advice:
Basically, using the stringtokenizer to break the string into tokens. If the token does not equal "add" or "sub" or if the token is a digit push it onto the stack... proceed to methods...
I believe that the problem is with the bolded section. I think it has something to do with the fact that I switched to using chars instead of the entire token. If the omit the bolded section and replace it with
stack.push(token);
and simply push it onto the stack it works fine; however, it does not meet my requirements. Can anyone advise on how to determine if a token is "add", "sub" or is a digit?
if(!token.equalsIgnoreCase("add"))
if(!token.equalsIgnoreCase("sub"))
{
[B] for(int i = 0; i < token.length(); i ++)
if(Character.isDigit(token.charAt(i)))
stack.push(token); [/B]
}
if(token.equalsIgnoreCase("add"))
add();
if(token.equalsIgnoreCase("sub"))
subtract();
Any assistance will be appreciated.
Thanks