创建堆栈以存储int值
class StackArray { int nbmax; int index; int[] array; /* N o w J a v a . c o m 提 供 */ // Constructors StackArray(int n) { this.nbmax = n; array = new int[nbmax]; index = -1; System.out.println("Succesfully created a stack array object..."); } // Methods void Push(int element) { if (index < nbmax - 1) array[++index] = element; } /*时 代 J a v a - nowjava.com 提供*/ int Pull() { if (index >= 0) return array[index--]; else return -1; } } public class Main { public static void main(String[] args) { StackArray myStack = new StackArray(10);