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;
}
```

Computer Science & Information Technology

You might also like to view...

What advantages does the CSS Designer have over the Code Navigator in

troubleshooting CSS styling? What will be an ideal response?

Computer Science & Information Technology

Output __________ are typically used to increase the efficiency of an application by sending larger amounts of data fewer times.

a. objects. b. broadcasters. c. buffers. d. None of the above.

Computer Science & Information Technology