1. package raptor;
  2.  
  3. import java.util.Stack;
  4.  
  5. public class test2 {
  6.  
  7. static Stack<Integer> stack = new Stack<Integer>();
  8. public static void main(String args[]) {
  9. System.out.println(whoKnows(5));
  10. }
  11.  
  12. static int whoKnows(int n) {
  13. System.out.println("Winding stack");
  14.  
  15. for (int i = n; i > 0; i--) {
  16. System.out.println("Pushing " + i + " onto the stack.");
  17. stack.push(i);
  18. }
  19.  
  20. System.out.println("Unwinding stack");
  21.  
  22. int result = 0;
  23. while(!stack.empty()) {
  24. int value = stack.pop();
  25. System.out.println("Popped " + value + " from the stack.");
  26. result += value;
  27. }
  28.  
  29. System.out.println("The answer is " + result);
  30.  
  31. return result;
  32. }
  33.  
  34.  
  35. }
  36.