-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarysearch.java
More file actions
32 lines (31 loc) · 836 Bytes
/
binarysearch.java
File metadata and controls
32 lines (31 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class binarysearch
{
public static void BinarySearch(int arr[], int n)
{
int start =0;
int end= arr.length-1;
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]==n)
{
System.out.println("Found "+arr[mid]+" at "+mid);
return;
}
if(arr[mid]>n)
{
end=mid-1;
}
else{
start=mid+1;
}
}
System.out.println("NOT FOUND");
return;
}
public static void main(String[] args) {
int arr[]={1,2,3,4,5,55,66,77,88,99,101,111};
int n =0;
BinarySearch(arr,n);
}
}