/** * BinarySearch * * This class demonstrates a binary search. * Binary search examines the middle element first to * find the key. If the middle is key, then it returns * the subscript of the middle element. If the key is * greater than the middle element, then the search divides * examines the upper half of the array for the key. If * the key is less than the middle element, then the search * examines the lower half. BinarySearch follows this algorithm * until it finds the key or if the key is not located in * the array, it return -1. * @author Brad Rippe * @version 1.0 */ public class BinarySearch { public static void main(String[] args) { int[] intArray = new int[1000]; int[] intArray2 = new int[10000]; // fill the arrays for(int i=0; i array[mid]) low = mid+1; // examine the upper half else // key < array[mid] high = mid-1; // examine the lower half } return -1; } }