Question: Given the following method definition, will repeated calls to the search method for the same target find all occurrences of that target in the array?

Given the following method definition, will repeated calls to the search method for the
same target find all occurrences of that target in the array?
static int search(int[] array, int target, int numElements)
int index=0;
bool found=false;
while((!found) && (index < numElements))
{
if(array[index]== target)
found=true;
else
index++;
}
if(found==true)
return index;
else
return -1;
}
a. Yes
b. No
c. Impossible to tell without looking at the values of the array
d. It depends on the value of target.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!