subject

Consider the search method (of some class) below which is intended to return the index of the position in array a where key is found. If key is not in the array a, -1 is returned. public int search (int key){
int low=0;
int hight=a. length-1;
while (low<=high){
int mid=(low+high)/2;
int diff=a[mid]-key;
if (diff==0) // a[mid]==key
return mid;
else if (diff<0) //a[mid] low=mid+1;
else
high=mid-1;
}
return -1;
}
private int [ ] a;
Suppose:
a={8, 10, 1, 5, 7, 9, 6, 2}
What value will search return? Why?
8
4
3
-1
No value will be returned. An is thrown.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:30
Which number on the image above correctly indicates the name of a folder in this url? a.1b.2c.3d.4
Answers: 2
question
Computers and Technology, 22.06.2019 02:30
Write a program that takes in 3 inputs [players (int type), expected game time (double type), team (char type)] and calculates actual game time (double) based on the following conditions: if the number of players or the expected game time is less than or equal to zero, it should output wrong input if the number of players is greater than 0 and less than or equal to 6 and if they are on the â€r’ or â€r’ team, their game time will be 10% faster. and if they are on the â€b’ or â€b’ team, their game time will be 15% faster. and if they are on the â€y’ or â€y’ team, their game time will be 20% faster. and if they are on any other team, they will play 0% faster. if the number of players is greater than 6 but less than or equal to 12 and if they are on the â€r’ or â€r’ team, their game time will be 20% faster. and if they are on the â€b’ or â€b’ team, their game time will be 25% faster. and if they are on the â€y’ or â€y’ team their game time will be 30% faster. and if they are on any other team, they will play 0% faster. if the number of players is greater than 12 but less than or equal to 18 and if they are on the â€r’ or â€r’ team, their game time will be 30% faster. and if they are on the â€b’ or â€b’ team, their game time will be 35% faster. and if they are on the â€y’ or â€y’ team, their game time will
Answers: 2
question
Computers and Technology, 22.06.2019 15:00
Hyperactive media sales has 10 windows 7 laptop computers used by sales-people in the organization. each laptop computer has several customized applications that are used during the sales process as well as customer relationship management software. all of the applications on the laptops are difficult to configure and have large data files. if all of the laptops have current hardware, what is the easiest way to install windows 10 on them?
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
Which component acts as a platform on which application software runs
Answers: 2
You know the right answer?
Consider the search method (of some class) below which is intended to return the index of the positi...
Questions
question
Mathematics, 02.10.2020 15:01
question
English, 02.10.2020 15:01
question
Mathematics, 02.10.2020 15:01
question
English, 02.10.2020 15:01
question
Mathematics, 02.10.2020 15:01
Questions on the website: 13722361