• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah yeah
thanks all
 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic