-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathceiling.java
More file actions
34 lines (30 loc) · 884 Bytes
/
ceiling.java
File metadata and controls
34 lines (30 loc) · 884 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
33
34
package binary_serch;
import javax.swing.plaf.synth.SynthTextAreaUI;
import java.util.Scanner;
public class celling {
public static void main(String[] args) {
int []ar={1,2,3,4,5,6,77,8,8,99,9,7454,33543};
Scanner input = new Scanner(System.in);
System.out.println("ente the number the u need to search");
int a = input.nextInt();
int ans= celing(ar,a);
System.out.println(ans);
}
static int celing(int[]arr , int target){
int start=0;
int end = arr.length;
while(start <=end){
int mid = start + (end - start)/2;
if( target < arr[mid]){
end = mid -1;
}
else if (target > arr[mid ]){
start = mid +1;
}
else {
return mid ;
}
}
return start;
}
}