... output spaces for alignment
20            for (int i = 0; i < middle; i++) {
21               System.out.print("    ");
22            }
23            System.out.println(" * "); // indicate current middle
24
25            // if the element is found at the middle
26            if (key == data[middle]) {
27               location = middle; // location is the current middle
28            }
29            else if (key < data[middle]) { // middle element is too high
30              high = middle - 1; // eliminate the higher half
31            }
32           else { // middle element is too low
33              low = middle + 1; // eliminate the lower half
34            }
35
36            middle = (low + high + 1) / 2; // recalculate the middle
37         } while ((low <= high) && (location == -1));
38
39         return location; // return location of search key
40      }
41
42      // method to output certain values in array
43      private static String remainingElements( ...

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.