Involves Stack, push and pop

Hi, I have this exercise which I'm not sure how to approach:

Evaluate the following expresion, where '+' menas "push the following letter onto the stack," and '-' means "pop the top of the stack and print it": "+U+n+c+e+r+t+a-+i-+n+t+y+ -+r+u--+l+e+s"

publicclass Ex15{

publicstaticvoid main(String[] args){

Stack<String> stack =new Stack<String>();

String str ="+U+n+c+e+r+t+a-+i-+n+t+y+ -+r+u--+l+e+s";

}

}

Not sure if I'm supposed to use String.split() somehow in an if statement? How do I actually evaluate this so that I can push or pop where necessary? Any help appreciated

[986 byte] By [brettosm8a] at [2007-11-27 6:14:56]
# 1

I don't see the need for split here. Just get the character array from the String and spin through it (a for loop). In the for loop evaluate each character looking for your operators (+ and -) and then decide what to do.

When you encounter a + you should grab the next character, push it and advance your loop iterator by one.

cotton.ma at 2007-7-12 17:24:55 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks, it worked!
brettosm8a at 2007-7-12 17:24:55 > top of Java-index,Java Essentials,Java Programming...