The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
stack
Posted by: cday | September 7, 2009 @ 12:21am
Java Code
[
Download
]
package raptor; import java.util.Stack; public class test2 { static Stack<Integer> stack = new Stack<Integer>(); public static void main(String args[]) { System.out.println(whoKnows(5)); } static int whoKnows(int n) { System.out.println("Winding stack"); for (int i = n; i > 0; i--) { System.out.println("Pushing " + i + " onto the stack."); stack.push(i); } System.out.println("Unwinding stack"); int result = 0; while(!stack.empty()) { int value = stack.pop(); System.out.println("Popped " + value + " from the stack."); result += value; } System.out.println("The answer is " + result); return result; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.52 / 8
67 Votes
http://codebin.yi.org/370
page generated in 0.01 seconds