MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / findFloor

Method findFloor

Programs/CeilingFloor.java:20–33  ·  view source on GitHub ↗
(int arr[], int target)

Source from the content-addressed store, hash-verified

18 }
19
20 static int findFloor(int arr[], int target) {
21 int start = 0, end = arr.length - 1;
22 while (start <= end) {
23 int mid = start + (end - start) / 2;
24 if (target < arr[mid]) {
25 end = mid - 1;
26 } else if (target > arr[mid]) {
27 start = mid + 1;
28 } else {
29 return arr[mid];
30 }
31 }
32 return end;
33 }
34
35 public static void main(String[] args) {
36 int[] arr = {12, 18, 24, 30, 36, 42};

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected