How I implemented Binary Search in JAVA
Binary search is used to search a key element from multiple elements. Binary search is faster than linear search.
In case of binary search, array elements must be in ascending order.
So after taking the value from the user we will sort the array that is inserted.
Then we will use the algorithm of Binary Search to search the index of value we are searching.
Steps of my code
Step 1 - Enter the number of elements you want to enter ' X '.
Step 2 - Enter ' X ' number of integer elements.
after taking the input it will be sorted in ascending order automatically.
Step 3 - Enter the number you wanna search.
And you get the index number of the number you were searching.
Note: This is how I implemented and maybe there are some room for improvement. If you have any suggestion please let me. Thanks