At Westonci.ca, we provide clear, reliable answers to all your questions. Join our vibrant community and get the solutions you need. Get quick and reliable answers to your questions from a dedicated community of professionals on our platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
Sagot :
Answer:
class Main {
public static void main(String[] args) {
int[] values = {11,12,15,16,112,118,123,145};
int target = 15;
int min = 0;
int high = values.length-1;
boolean found = false;
int answer = 0;
int mid;
while(!found && min <= high) {
mid = (min + high) / 2;
if (values[mid] == target) {
found = true;
answer = mid;
} else if (target > values[mid]) {
min = mid + 1;
} else {
high = mid - 1;
}
}
if (found) {
System.out.printf("%d FOUND AT ARRAY INDEX %d", target, answer);
} else {
System.out.printf("%d was not found", target);
}
}
}
Explanation:
I altered the while expression to make the code work.
Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.