Question: Task #6 Binary Search Write a method to perform a binary search on an integer array. The method will return the position of the target

Task #6 Binary Search Write a method to perform a binary search on an integer array. The method will return the position of the target element in an array or return -1 if target is not found. Then, write a main method that creates and initializes a sorted array, asks the user for a target element, and locates the target in the array. Here are sample interactions. The user's input is shown in bold. $ java BinarySearch enter a number 10 array = [ 15 20 25 30 35 40 ] 10 is not in the array $ java BinarySearch enter a number: 15 array = [ 15 20 25 30 35 40 ] 15 is at position 0 $ java BinarySearch enter a number 20 array = [ 15 20 25 30 35 40 ] 20 is at position 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
