package JavaHW2;

/**
 * Created by vrom911 on 10/19/16.
 */
public class BinarySearch {
    public static void main(String[] args) {
        int x = Integer.parseInt(args[0]);
        int[] m = new int[args.length - 1];
        for (int i = 0; i < args.length - 1; i++) {
            m[i] = Integer.parseInt(args[i+1]);
        }
//        System.out.println(normalSearch(m, x));
        System.out.println(recursiveSearch(m, x, 0, m.length));
    }

    public static  int normalSearch(int[] m, int x) {
        int idxL = 0, idxR = m.length ;
        int mid;
        while (idxL + 1 < idxR) {
            mid = (idxL + idxR) / 2;
            if (m[mid] > x) {
                idxL = mid;
            } else {
                idxR = mid;
            }
        }
        if (idxL+1 == idxR &&  m[idxL] <= x) {idxR = idxL;}
        return idxR;
    }
    public static int recursiveSearch(int[] m, int x, int idxL, int idxR) {
        if (idxL + 1 < idxR)  {
            int mid = (idxL + idxR) / 2;
            if (m[mid] > x) {
                return recursiveSearch(m, x, mid, idxR);
            } else {
                return recursiveSearch(m, x, idxL, mid);
            }
        } else {
            if(idxL+1 == idxR && m[idxL] <= x ) {idxR = idxL;}
            return idxR;
        }

    }
}
@@ -308,17 +308,19 @@
 t(args%5Bi
-+
+ + 
 1%5D);%0A   
@@ -525,26 +525,8 @@
  = 0
-, idxR = m.length 
 ;%0A  
@@ -535,19 +535,31 @@
     int 
-m
 id
+xR = m.length
 ;%0A      
@@ -598,16 +598,20 @@
         
+int 
 mid = (i
@@ -770,25 +770,27 @@
     if (idxL
-+
+ + 
 1 == idxR &&
@@ -789,17 +789,16 @@
  idxR &&
- 
  m%5BidxL%5D
@@ -805,16 +805,29 @@
  %3C= x) %7B
+%0A            
 idxR = i
@@ -822,32 +822,41 @@
     idxR = idxL;
+%0A        
 %7D%0A        return
@@ -1231,14 +1231,17 @@
   if
+ 
 (idxL
-+
+ + 
 1 ==
@@ -1265,24 +1265,53 @@
 %3C= x
- 
 ) %7B
-idxR = idxL;
+%0A                idxR = idxL;%0A            
 %7D%0A  
@@ -1339,20 +1339,19 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%7D

Reformat code