import java.util.Random;
import java.util.Scanner;

import static java.util.Arrays.copyOf;

public class BinarySearch {

    private static int MAX_ALLOWED_NUMBER = 99;

    public static void main(final String[] args) {
        final Scanner input = new Scanner(System.in);

        System.out.print("Array length: ");
		final int[] array = bubbleSort(getRandomArray(input.nextInt()));
        printArray("Array", array);

        System.out.print("To find: ");
        search(array, input.nextInt());
    }


    private static int[] getRandomArray(final int len) {
		final Random rand = new Random();
		final int[] randomArray = new int[len];

		for (int i = 0; i < randomArray.length; ++i) {
			randomArray[i] = rand.nextInt(MAX_ALLOWED_NUMBER);
		}

		return randomArray;
	}


    private static void printArray(final String caption, final int[] array) {
		System.out.print(caption + ":\t\t");

		for (final int elem : array) {
			System.out.print(elem + "\t");
		}

		System.out.println();
	}


    private static int[] bubbleSort(final int[] sArray) {
		int[] bblArray = copyOf(sArray, sArray.length);
		int tmp;

		for (int i2 = 0; i2 < bblArray.length; i2++) {
			for (int i = 0; i < bblArray.length - 1; i++) {
				if (bblArray[i] > bblArray[i + 1]) {
					tmp = bblArray[i];
					bblArray[i] = bblArray[i + 1];
					bblArray[i + 1] = tmp;
				}
			}
		}

		return bblArray;
	}


    private static void search(final int[] array, final int search) {
        int startBound, endBound, middle;
        startBound = 0;
        endBound = array.length;

        while (true) {
            middle = (endBound + startBound) / 2;
            System.out.println("middle = " + middle);

            if (array[middle] == search) {
                System.out.println("FOUND, i = " + middle);
                break;
            } else if (array[middle] < search) {
                startBound = middle;
            } else if (array[middle] > search) {
                endBound = middle;
            }
        }
	}


}

@@ -313,18 +313,24 @@
 th: %22);%0A
-%09%09
+        
 final in
@@ -567,18 +567,24 @@
  len) %7B%0A
-%09%09
+        
 final Ra
@@ -609,18 +609,24 @@
 ndom();%0A
-%09%09
+        
 final in
@@ -658,18 +658,24 @@
 %5Blen%5D;%0A%0A
-%09%09
+        
 for (int
@@ -713,19 +713,28 @@
  ++i) %7B%0A
-%09%09%09
+            
 randomAr
@@ -776,23 +776,35 @@
 UMBER);%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 return r
@@ -811,25 +811,28 @@
 andomArray;%0A
-%09
+    
 %7D%0A%0A%0A    priv
@@ -901,18 +901,24 @@
 rray) %7B%0A
-%09%09
+        
 System.o
@@ -947,18 +947,24 @@
 t%5Ct%22);%0A%0A
-%09%09
+        
 for (fin
@@ -986,19 +986,28 @@
 rray) %7B%0A
-%09%09%09
+            
 System.o
@@ -1029,23 +1029,35 @@
  %22%5Ct%22);%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 System.o
@@ -1070,17 +1070,20 @@
 ntln();%0A
-%09
+    
 %7D%0A%0A%0A    
@@ -1136,18 +1136,24 @@
 rray) %7B%0A
-%09%09
+        
 int%5B%5D bb
@@ -1192,18 +1192,24 @@
 ength);%0A
-%09%09
+        
 int tmp;
@@ -1210,18 +1210,24 @@
 t tmp;%0A%0A
-%09%09
+        
 for (int
@@ -1265,19 +1265,28 @@
 i2++) %7B%0A
-%09%09%09
+            
 for (int
@@ -1325,20 +1325,32 @@
  i++) %7B%0A
-%09%09%09%09
+                
 if (bblA
@@ -1382,37 +1382,67 @@
 ) %7B%0A
-%09%09%09%09%09tmp = bblArray%5Bi%5D;%0A%09%09%09%09%09
+                    tmp = bblArray%5Bi%5D;%0A                    
 bblA
@@ -1472,13 +1472,28 @@
 1%5D;%0A
-%09%09%09%09%09
+                    
 bblA
@@ -1515,26 +1515,59 @@
 mp;%0A
-%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09
+                %7D%0A            %7D%0A        %7D%0A%0A        
 retu
@@ -1579,17 +1579,20 @@
 lArray;%0A
-%09
+    
 %7D%0A%0A%0A    
@@ -2209,9 +2209,12 @@
   %7D%0A
-%09
+    
 %7D%0A%0A%0A

fix tabs