I have to write a program that reads a postfix expression from the keyboard and store it in a stack. I keep getting a class cast exception at case "+" : and I can not figure it out. Is anyone able to help me?
String option = (String)stack.pop();
while( stack != null )
{
switch( option )
{
case "+":
int left = (Integer)stack.pop();
int right = (Integer)stack.pop();
int result = left + right;
String temp = (String) stack.pop();
stack.push(result);
break;
Aucun commentaire:
Enregistrer un commentaire