Binary Search in Java Program

Binary Search in Java

Binary search is a more efficient searching algorithm, in comparison to linear search. It repeatedly divides the search range in half until it finds the target element. Below is how you can perform a Binary Search in Java program:

Binary Search in Java program

Output

C:\CodeRevise\java>javac BinarySearch.java

C:\CodeRevise\java>java BinarySearch
Enter the number of elements : 5
Input 5 numbers :
10
20
35
45
68
Input the number to search : 45
Element 45 exist at index 3

 

 

Check out our other Java Programming Examples

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top