Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

k&b scjp5, page no 616, problem no 9

 
Mukesh Gulia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given a properly prepared String array containing five elements, which range of results could a proper invocation of Arrays.binarySearch()produce?

a. 0 through 4
b. 0 through 5
c. -1 through 4
d. -1 through 5
e. -5 through 4
f. -5 through 5
g. -6 through 4
h. -6 through 5

ans is G.
i thought answer is be E

range can be ((-5) -1) through 4 i.e. 4 to 4
negative result give insertion point(array index).
please confirm.
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know

range can be ((-5) -1) through 4 i.e. 4 to 4


then range is -6 to 4.
 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

............................................................................

range can be ((-5) -1) through 4 i.e.
((-5)+(-1))= (-5-1)= -6
i.e range can be -6 through 4

you did a slight mistake in adding.
 
Mukesh Gulia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah yeah
thanks all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic