// Among indexes first...last, return index of the target. // If target is not present then return -1. // precondition: the elements of array are in descending order. static int find(int [] array, int first, int last, int target) if (first > last) { // one very short line } if (first == last) { // one line, using the conditional operator } int mid = (first+last+1)/2; %3D if (target <= array[mid]) { // one line, involving a recursive call } // one line, involving a recursive call
In java
i have some code for a method that finds the index of an integer that is passed in thet int is (target) the method also has the array called (array) and the first and last element of the array. also for this method to work the array has to be in descending order
"static int find(int [] array, int first, int last, int target)"
thats the method with all the variables that are passed to it
my guess is that the first if statement just will have a short line that is
"return -1;" because since the array has to be in descending order the first element cant be greater then the last element in the array but im confused on the rest because i cant find a way to make them one line codes with the conditions that i have to meet in the comments any help would be aprreaciated
![// Among indexes first...last, return index of the target.
// If target is not present then return -1.
// precondition: the elements of array are in descending order.
static int find(int [] array, int first, int last, int target)
if (first > last) {
// one very short line
}
if (first == last) {
// one line, using the conditional operator
}
int mid = (first+last+1)/2;
if (target <= array[mid]) {
// one line, involving a recursive call
}
// one line, involving a recursive call](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ffedcb44c-84a8-400b-a03e-cc7fbcfb040d%2Fb3997592-0965-456f-bab0-74965d17fa4d%2Fhcoqqp_processed.png&w=3840&q=75)

Step by step
Solved in 2 steps with 1 images









