Simplify the program a bit by storing the result into StringBuilder directly without using the stack.