import java.util.*;import javax.swing.*;public class binary_search{ public static void main(String[] args) { int myNums[]={2, 44, 5, 66, 78, 90, 23, 66}; int point, find = 78; point = Arrays.binarySearch(myNums, find);
System.out.println("Element found at index " + point);
}}Using the above code, what output will be displayed when the program is executed? Describe how the binarySearch() method functions.
What will be an ideal response?
When executed, the println statement will display the following:?Element found at index 4?The Arrays class binarySearch() methods provide a way to search through sorted lists of values of various data types. It is important that the list be in order before you use it in a call to binarySearch(); otherwise, the results are unpredictable. The binarySearch() method functions as follows:?You have a sorted array (myNums) and an item (find = 78) for which you are searching within the array.?Based on the array size, you determine the middle position. (In an array with an even number of elements, this can be either of the two middle positions.)?You compare the item you are looking for with the element in the middle position of the array and decide whether your item is above that point in the array-that is, whether your item's value is less than the middle-point value.?If it is above that point in the array, you next find the middle position of the top half of the array; if it is not above that point, you find the middle position of the bottom half. Either way, you compare your item with that of the new middle position and divide the search area in half again.?Ultimately, you find the element or determine that it is not in the array.
You might also like to view...
Analyze the following code:
``` public class Test { public static void main(String[] args) throws MyException { System.out.println("Welcome to Java"); } } class MyException extends Error { } ``` a. You should not declare a class that extends Error, because Error raises a fatal error that terminates the program. b. You cannot declare an exception in the main method. c. You declared an exception in the main method, but you did not throw it. d. The program has a compile error.
A(n) ____________________ is a security device or a program that protects a network by inspecting and filtering the incoming data packets or applications and either allowing or rejecting them to enter the network.
Fill in the blank(s) with the appropriate word(s).
JavaScript has a function called ____ that returns a True value if a string cannot be converted to a number.
A. isNumeric(str) B. isNaN() C. numberToString(num) D. isLetter(str)
Today, more than ____ U.S. households have no landline-based phone, and that percentage is growing rapidly.
A. 10% B. 15% C. 25% D. 50%