... elements
26        private static void swap(int[] data, int first, int second) {
27           int temporary = data[first]; // store first in temporary
28           data[first] = data[second]; // replace first with second
29           data[second] = temporary; // put temporary in second
30        }
31
32        // print a pass of the algorithm
33        private static void printPass(int[] data, int pass, int index) {
34           System.out.printf("after pass %2d: ", pass);
35
36           // output elements till selected item
37           for (int i = 0; i < index; i++) {
38              System.out.printf("%d  ", data[i]);
39           }
40
41           System.out.printf("%d* ", data[index]); // indicate swap
42
43           // finish outputting array
44           for (int i = index + 1; i < data.length; i++) {
45              System.out.printf("%d  ", data[i]);
46           }
47
48           System.out.printf("%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.