This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B SCJP 5 Study Guide p628 problem 9

 
Harry Henriques
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Answer:

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
answer -6 through 4

Is this correct?
 
Harry Henriques
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a question?? You didn't write anything apart from the code and the output...
 
Harry Henriques
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic