About Question com.enthuware.ets.scjp.v6.2.92 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Aditya553
Posts: 15
Joined: Sun Aug 06, 2017 2:37 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.92 :

Post by Aditya553 »

Still, i'm unable to understand why we get -5 to 3 .Pls, explain in a simpler manner.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.92 :

Post by admin »

When you search for a string in a sorted list, there are two possibilities -
1. the string is found : In this case, it will return the index at which it was found.
2. the string is not found: In this case, it will return one more than the index at which this string will be inserted if you try to insert it in the list but with a minus sign.

In the given list, if you search for "xxxx", what will happen? It is not in the list, so the sign will be minus. And if you try to insert it, it will be inserted at index 5. So the return value will be -5.
If you like our products and services, please help us by posting your review here.

Aditya553
Posts: 15
Joined: Sun Aug 06, 2017 2:37 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.92 :

Post by Aditya553 »

i understood about -5 but why 3

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.92 :

Post by admin »

What all elements are there in the list? What will it return if you search for those elements? Apply the same logic given above.
If you like our products and services, please help us by posting your review here.

sijucm
Posts: 8
Joined: Tue Jan 11, 2022 4:41 am

Re: About Question com.enthuware.ets.scjp.v6.2.92 :

Post by sijucm »

I cannot think of any string that can come in between a and aa and aaa and aaaa. Could you give an example in which it can give -2, -4, -3, etc?
But if you do this, then you get -1. System.out.println(Arrays.binarySearch(sa, "1"));
According to what I understand, these are the values possible -5 (if higher), -1 (if less), 0, 1, 2, 3

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.92 :

Post by admin »

Well, you can try searching for these strings - a1, aa1, and aaa1 and see what you get.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests