- Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathExercise_1.java
More file actions
Latest commit
21 lines (20 loc) · 677 Bytes
/
Copy pathExercise_1.java
File metadata and controls
21 lines (20 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
classBinarySearch {
// Returns index of x if it is present in arr[l.. r], else return -1
intbinarySearch(intarr[], intl, intr, intx)
{
//Write your code here
}
// Driver method to test above
publicstaticvoidmain(Stringargs[])
{
BinarySearchob = newBinarySearch();
intarr[] = { 2, 3, 4, 10, 40 };
intn = arr.length;
intx = 10;
intresult = ob.binarySearch(arr, 0, n - 1, x);
if (result == -1)
System.out.println("Element not present");
else
System.out.println("Element found at index " + result);
}
}