// used to gain access to System.out import java.io.*; public class Stack { // place to store data (an example of a one line comment) private int [] data; /* how many things are currently in the stack. (example of multi line comment) */ private int stack_size = 0; // constructor public Stack(int size) { // this is where you actually create the array. // it does not exist before here. data = new int[size]; } // maybe should return a boolean to indicate success public void push(int new_top) { // insert the data into the array data[stack_size] = new_top; // increment the current count stack_size++; } public int pop() { // decrease the current count. // you could also do this later but it makes it a bit more compact // if you do it here. stack_size--; // return the value to the user return data[stack_size]; } // the program that actually runs the program public static void main(String[ ] args) { // create the Stack Stack s = new Stack(3); // add some data s.push(1); s.push(2); s.push(3); // print out some data System.out.println(s.pop()); System.out.println(s.pop()); } }