# K&B SCJP 5 Study Guide p628 problem 9

Harry Henriques
Ranch Hand
Posts: 206
I don't know how to search for a solution to this problem. I'm sure that this question has been asked before.

9. Given a properly prepared String array containing five elements, which range of results could a proper invocation of Arrays.binarySearch() produce.

int[] arr = new int[5];
arr[0] --> 0 or -1
arr[1] --> 1 or -2
arr[2] --> 2 or -3
arr[3] --> 3 or -4
arr[4] --> 4 or -5
after arr[4] --> -6

Is this correct?

Harry Henriques
Ranch Hand
Posts: 206

C:\Documents and Settings\Harry Henriques>java BinarySearch
int [] ia = new int []{ 2, 4, 6, 8, 10 };
insert 1 at index 0 is -1
ia[0] = 2 at index 0
insert 3 at index 1 is -2
ia[1] = 4 at index 1
insert 5 at index 2 is -3
ia[2] = 6 at index 2
insert 7 at index 3 is -4
ia[3] = 8 at index 3
insert 9 at index 4 is -5
ia[4] = 10 at index 4
insert 11 at index 5 is -6

Ankit Garg
Sheriff
Posts: 9509
22
Is this a question?? You didn't write anything apart from the code and the output...

Harry Henriques
Ranch Hand
Posts: 206
Ankit Garg wrote: Is this a question?? You didn't write anything apart from the code and the output...

Ankit, I looked at the links that you provided, but the answers to my question weren't easy for me to understood. I thought that I could provide a better answer to my own question, and I tried to do so with this example code and output. Maybe this code snippet will help someone else.

Harry