Appendix D. Solutions to Programming Exercises
1 Basics of Java Programming
1.1 The printStackElements()
method of the PrintableCharStack
class does not pop the elements.
// File: CharStack.javapublic class CharStack { // Instance variables: protected char[] stackArray; // The array implementing the stack. protected int topOfStack; // The top of the stack. // Static variable private static int counter; // (1) // Constructor now increments the counter for each object created. public CharStack(int capacity) { // (2) stackArray = new char[capacity]; topOfStack = -1; counter++; } // Instance methods: public void push(char ...
Get A Programmer’s Guide to Java® SE 8 Oracle Certified Associate (OCA) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.