import java.io.*; public class BinVyhled { public static void main(String[] args) throws IOException { BufferedReader vstup; vstup = new BufferedReader(new InputStreamReader(System.in)); int[] pole = {2, 5, 6, 8, 9, 15, 23, 45, 67, 89, 95, 96, 97}; int i,l,r,x; int n = pole.length; boolean nalezen = false; // Vypsani pole for (int j = 0; j < pole.length; j++) { System.out.print(pole[j]+" "); } System.out.println(); // Hledane cislo System.out.print("Zadejte hledane cislo: "); x = (new Integer(vstup.readLine())).intValue(); l = 0; r = n; // Binarni vyhledavani do { i = (l+r) / 2; if (pole[i] == x) { System.out.println("Hledany prvek se nachazi na pozici " +(i+1)); nalezen = true; } if (pole[i] > x) { r = i - 1; } else { l = i + 1; } } while ((l <= r)&(nalezen == false)&(l<(n-1))); if (nalezen == false) { System.out.println("Hledany prvek nenalezen."); } vstup.close(); } }