Skip to content

Commit 8a90ae3

Browse files
Add files via upload
1 parent 4c73eaa commit 8a90ae3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Binarysearch.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
public class Binarysearch
3+
{
4+
public static int getposition(int nums[],int key){
5+
int start=0; int end=nums.length-1;
6+
while(start<=end){
7+
int mid=(start+end)/2;
8+
if(nums[mid]==key){
9+
return mid;
10+
}
11+
else if(nums[mid]<key){
12+
start= mid+1;
13+
}
14+
else{
15+
end=mid-1;
16+
}
17+
}
18+
return -1;
19+
}
20+
public static void main(String[] args) {
21+
//System.out.println("Hello World");
22+
int nums[]={1,4,7,8,7,5,8};
23+
int key=7;
24+
int mid=getposition(nums,key);
25+
System.out.println(mid);
26+
}
27+
}

0 commit comments

Comments
 (0)