February 2014
Beginner
1248 pages
62h 25m
English
Class BinarySearchTest (Fig. 19.3) contains:
• static method binarySearch to search an int array for a specified key
• static method remainingElements to display the remaining elements in the array being searched, and
• main to test method binarySearch.
The main method (lines 57–90) is nearly identical to main in Fig. 19.2. In this program, we create a 15-element array (line 62) and line 67 calls the Arrays class’s static method sort to sort the array data’s elements in an array in ascending order (by default). Recall that the binary search algorithm will work only on a sorted array. The first line of output from this program shows the sorted array of ints. When the user instructs the program to search for ...
Read now
Unlock full access