... "%s%s%d)%n%s", operation,
58            " (buffer cells occupied: ", occupiedCells, "buffer cells:  ");
59
60         for (int value : buffer) {
61            System.out.printf(" %2d  ", value); // output values in buffer
62         }
63
64         System.out.printf("%n            ");
65
66         for (int i = 0; i < buffer.length; i++) {
67            System.out.print("---- ");
68         }
69
70         System.out.printf("%n            ");
71
72         for (int i = 0; i < buffer.length; i++) {
73            if (i == writeIndex && i == readIndex) {
74               System.out.print(" WR"); // both write and read index
75            }
76            else if (i == writeIndex)
77               System.out.print(" W   "); // just write index
78            }
79            else if (i == readIndex) {
80               System.out.print("  R  "); // just read index
81            }
82            else {
83               System.out.print("   "); // neither index
83            }
85         }
86
87         System.out.printf("%n%n"); ...

Get Java How To Program, Late Objects, 11th Edition 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.