1 Reply Latest reply: Mar 1, 2007 2:29 AM by 807606 RSS

    casting problems

    807606
      Say that I have a stack of character, and I want to extract the value of those stack into an integer. How can I do that??

      below is my code:
      public int value() {
                int result = 0;
                char right = ' ';
                char left = ' ';
                int number = 0;
                String temp = this.postfix();
                Stack<E> s = new Stack<E>();
                for (int i = 0; i<temp.length(); i++){
                     char c = temp.charAt(i);
                if (c != '+' && c != '-' && c != '/' && c != '%' && c != '*' && c!= '(' & c!= ')')
                     s.push(c);
                else if (c == '+' && c == '-' && c == '/' && c == '%' && c == '*') {
                     right = s.pop();
                     left = s.pop();
                number = left + s.pop() + right;
                s.push(number);
                }
                     
                return result;
           }