Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. You may assume that the array is sorted, and your method should use a binary search..
What will be an ideal response?
```
public boolean binarySearch(int a, int[] array)
{
int first = 0;
int last = array.length-1;
int mid;
while(first <= last)
{
mid = (first+last)/2;
if(array[mid] == a)
return true;
else if(array[mid] > a)
last = mid - 1;
else
last = mid + 1;
}
return false;
}
```
You might also like to view...
How many /64 networks can be assigned from a /60 network address prefix?
A. 16 B. 4096 C. 65536 D. 32768
If the yellow message bar appears near the top of your browser window, your system has:
A) detected a page fault. B) linked to a page that is no longer active. C) performed an illegal operation. D) restricted ActiveX controls.
Write the style rule to center an h1 tag on a page
What will be an ideal response?
What command can be used to repair a dual boot system?
A. bootsect B. bootrec C. bcdedit D. bootrep