public class FindB extends MiniJava {
    public static int[] readArray(int number) {
        // number = Anzahl zu lesender Elemente
        int[] result = new int[number]; // Feld anlegen
        for (int i = 0; i < number; ++i) {
            result[i] = read();
        }
        return result;
    }

    public static int find0(int[] a, int x, int n1, int n2) {
        int t = (n1 + n2) / 2;
        if (a[t] == x) 
            return t;
        else if (n1 == n2)
            return -1;
        else if (x > a[t])
            return find0(a, x, t+1, n2);
        else if (n1 < t)
            return find0(a, x, n1, t-1);
        else return -1;
    }   

    public static int find(int[] a, int x) {
        return find0(a,x,0,a.length-1);
    }   

    // Jetzt kommt das Hauptprogramm
    public static void main(String[] args) {
        int n = read("Länge des Arrays");
        int[] arr = readArray(n);

        int x = read("Zu suchende Zahl");

        int res = find(arr,x);
        if (res == -1)
            write("Zahl nicht gefunden!");
        else
            write("Zahl an Position "+res+" gefunden");
    } // end of main()    
}


